Using UMG for change materials

Hi, first of all, I know there are other questions about this matter. But I wasnt able to achieve what I want yet. I tried youtube tutorials and different methods, its been weeks and I dont know what to do.

I’ll post what I have and what I want.

1 - I have this desk. I want to approach it in game, click it -or interact with it, whatever- and then a UMG menu appears which lets me select a new material for it.

http://a.pomf.se/ycxweg.jpg

2 - So I started creating this UMG menu. I’m showing both Designer and Graph Editor. I only have it for one button for the moment.

http://a.pomf.se/qibizo.jpg

3 - Then I get to the Level Blueprint. I choose my UMG in “Create**Widget” , set the mouse cursor to true, etc. So now my menu appears whenever I press Play.

http://a.pomf.se/tfvcre.jpg

4 - Now I create a Blueprint for my desk. For parts :

  • Construction Script
    I create one script named Dynamic Material. I dont really know if Im doing this right.

http://a.pomf.se/lwcnnp.jpg

  • Graph Editor
    This is where I get lost. I have to relate my widget to this Blueprint, but I dont know how.

http://a.pomf.se/teolsn.jpg

For names :
colors is my widget and barra is my static mesh (desk).
If you can guide me or point me to a tutorial or somewhere else to look, I’m totally stuck.

Thanks in advance!

I’m not sure if you’ve seen this answer yet, but it deals exactly with what you are trying to accomplish.

Thats the one Im actually using as a reference for the last week! I think I have everything right except this part. I dont know how to continue.
For example - Mesh from persistent level, I cant get that inside my desk_BP.
Or I cant create the Add from Viewport node inside the blueprint.

I think all the others blueprints work fine, the desk mesh is what is giving me problems.

In the example from that answer, the staticMeshActor was made into a blueprint, I strongly suggest you perform the same steps outlined in there, except replace the cone references with your desk references.

That way you will properly have a Desk_BP which you could drag into your level as many times as you wanted and still retain that functionality instead of using a level blueprint for all the work.

Sorry but thats exactly where I dont know how to proceed.
I created a Desk_BP from the staticmesh (point 4) and another BP for the UMG menu. (point 2)
Then I tried following every step but I cant get the same nodes.

http://a.pomf.se/evklqo.jpg

Sorry again to bother but every step I take Im more and more confused.

Your confusion is probably stemming from the two variants.

Variant 1 - Feb 10 '15 at 2:00 PM

This one uses the level blueprint and assumes that is the only object that will ever need it. Using level blueprints is not ideal, so scrap the knowledge you got from this Variant.

Variant 2 - Feb 26 '15 at 1:06 PM

This one uses a blueprint for the object. If you take a look at the first image, that code is part of the BP, NOT the level. That’s why after I created the widget it gets assigned self (because self is the StaticMeshActor we made a BP out of).

The widget itself does NOT change at all. The only thing that does is Level BP is no longer used and we moved the code to the StaticMeshActor instead.

I see, I think I’m getting it.
I followed the steps from feb26 and discarted my level blueprint. Can you look one more time to my bp?

http://a.pomf.se/gmpflw.jpg

1 - I cant connect those nodes, I’m afraid I did something wrong.
2 - I named my umg widget “colors”, do I have to use that same node in all the places I marked?

Thanks again for your patience

Hello Aian,
I have been struggling with implementing Justin’s logic into my BP like you for 2 days. It was so simple, it seems I lack some basic understanding of creating communication between BP’s. Since we both tried different logics, I suggest you to try this out in an empty level to figure out BP communication basics without headache.

I had to use Level BP for this for some reasons, here is how I achieved that step by step. Again, this is just a workaround to implement Justin’s work :slight_smile: Thanks mate!

UMG Event Graph

  1. In my UMG, I created a variable called wallWidget. Changed its variable type into Static Mesh Actor. and made it Public from clicking the closed eye icon from Variables panel, making it Public to other BP’s so they can get this value
  2. On my button click event, I created a Set Material node and connected my variable with GET, to Target node. It will convert the variable into Static Mesh Component

On Level Blueprint

  1. Create a new node by right clicking into empty canvas. Write down the variable name we created (in this case, wallWidget). If it is not appearing in the list, be sure you uncheck Context Sensitive. Click the Set wallWidget.

  2. Drag and drop your desired object into Blueprint from the World Outliner, where your ingame stuff listed.

  3. Connect the node into Set Wall Widget’s Wall Widget slot

  4. Add this node in between Create Widget and Add to Viewport nodes.

  5. Connect the Create Widget’s Return Value into the Target slot in Set Wall Widget

If you managed to do it correctly, it should work :slight_smile: Again, thanks to Justin for the logic behind this Blueprint!

Justin,

Is there any way you could make a quick video of the steps you’ve taken to create this? I’ve jumped back and forth between the two posts that explain this but the translation still gets lost. There are no tutorials online that show this and I think it would be incredibly helpful, not only for me but for a number of people trying to achieve this.

Hi CSanderman,
I managed to do this and explained it step-by-step below the page. It is basicly what Justin did there, I just explained the BP communication part further. If you are still having trouble, just ask about which part you couldn’t do.

Hello Excalith, Could you please provide us with some screenshots?

Hello, unfortunately I am on a vacation. If you tell me where you got stuck, I will try to help you

Hello, I’m trying to change a blueprint actor material using Widget.
while playing. when I click on the actor, it opens the interface of three buttons for instance, blue, red and exit.

I tried every method I saw on youtube and here to set the buttons to change material or texture when click on them… It’s just not working!

Anyway. inside the widget, I could only change “the vector parameter value”
But i want to set a new material or texture :confused:

I could change the materials from inside the actor blueprint, but I can’t do that from the widget… calling an event or not very sure how to do it

I think my main problem is that I’m not very experienced in blueprints… I’m sure I’m missing something…

About your steps, I could follow them until step 4.
After creating the “WallWidget” set node in the level blueprint, I dragged my object from the scene into the level blueprint and connected it into the node slot “WallWidget”.
I couldn’t place the in between “Create Widget” and “Add to viewport”
thank you

I create one video for you man :slight_smile: HERE THE VIDEO LINK

much appreciate sir!
it’s totally working!

Hello, I followed your steps and finally could get the things working, thanks so much.
Now, I’m trying to apply the same material change to many actors (from different classes, but all of them are static mesh actors), so I turned the variable that holds my static mesh references into an array variable, and made an array (in level blueprint) containing my meshes, plugged the array’s output to the array variable’s input, but the material change just affects to the first actor on the list. I’m new to not just UE4 but also to game development suites, could you please tell me what’s wrong here?, am I lacking one node?, am I misunderstanding the use of the array node?, is there a better way to apply this material change to different actors at once?

I’m having a similar issue but my setup is different. I have the HUD as a widget and I’m trying to get the buttons to change the material of a blueprint I already have set up. I’m not sure my variable is correct.

Not sure what I’m doing wrong. I’m a bit of a noob.

Use get all actors of class to get your actor and set the material.