Change material by selecting a button

Hi, Ive been trying to do this for several weeks already. I watched almost every tutorial and the answerhub but I cant figure out how to build this blueprint.

I’ll try to explain step by step what I have at this moment and what I want to achieve the best I can.

1- So I have this desk.
I create a blueprint and add that sphere as a variable -named ClickEventMesh- So I want to click the sphere and then a menu appears for selecting the new material.

2- In the desk BP, I create this Construction Script and name it Dynamic Material.

3- Then I create a HUD with 2 buttons, each one for a single new material. This step could be much easier in UMG but somehow I couldnt link onClicked button with my desk BP.

4- Finally this is the Graph Editor of the desk BP.

Everything compiles fine but when I start the game nothing happens. I dont even know if Im doing this right. Is there any tutorial for creating a widget with buttons for changing the material? This is driving me crazy :frowning:

Thanks in advance


never tried something like this before but i can see you got some wrong setup in your last shot. In the event tick, from the Cast to ArchvizHUD you create a “set color” node but you never execute it. Whenever you want to use a node with execution pins (white triangles) you have to have it connected to the execution flow. So in this case you’d want to connect you “set color” node between the “Cast to” and the “Set Vector Param Value”.

Dunno if that will solve your problem but atleast will make that node work correctly.

Thank you Meguido, but that didnt work. I can set the color by pressing the button or MakeLinearColor but it doesnt change anything.

You can modify step 2 CreateDynamicMaterialInstance, and set the material type there and set the element ID to the id of the mesh to change starting at 0. You can loop through an array of material instances to choose your material type.


In order to change the material for the object, you’re going to need a reference to the object’s mesh, like you’ve done with your desk. This example will change the player material.


Working with the construction graph is great for setting your materials on game objects in the editor without compiling. Just turn your variables to editable and expose on spawn.

Hey Aian,

this looks like something I’ve tried to solve once before. I didn’t make much in the lines of a tutorial, but the blueprints themselves should be easy enough to follow. It lets you click on an object, then a menu pops open that lets you choose a new material for whatever you clicked on. The previous topic is over here:

From there it wouldn’t be hard to create a custom list of materials for each individual item if you so desired with the use of arrays on the items that hold the material values, that would get fed into the HUD blueprint where you actually set the new materials. Of course if you want to dynamically change the material’s values (colours or brightness or whatever) you’d still need a dynamic material instance for those and it’d be easier to just do everything in UMG with some kind of sliders or knobs. But this should be adequate for basic static material picking.

Thank you both for your answers.
I find your script very useful Bohrium but I think its too complicated for me. I want to create a UMG menu with buttons and then manage all the design from there. Anyway I’ll keep your link in my favorites folder for the future.

I found this in the answerhub Changing the Materials using UMG Buttons - UE4 AnswerHub and its very similar to what I’m trying to make. So I tried to recreate it. I hope this can finally work, I’m so tired!. Sorry for suddenly changing the blueprint.
These may be noob questions but Im at the point where I dont know how to continue.

I created 3 blueprints.
1 - Staticmesh BP.
This is the desk and where I have most of my problems. I’m using the reference image but I dont know how to create a staticmesh from persistent level inside my BP. I usually selected the mesh in the viewport, rightclick in graph editor and add it from there. But I cant do it right here. Maybe its the wrong window? I dont have a clue.
Besides that, those Widget nodes, are the same all of them? I think so, but… who knows at this point :rolleyes:

2 - Widget BP
Ok, I created a simple menu in UMG, selected one of the buttons, and added that BP.

3 - Level BP
And finally this one, for making the BP start when I press play. I’m assumming everything is fine but again, who knows.

Is there anything else I need to do? Additional Construction Scripts? More Blueprints? I tried following the answerhub link but Im getting lost in every step.
When I press play it doesnt work :(. HUD appears, but pressing the buttons does nothing.

Did you ever resolve this? I am trying to create the exact same thing.

Bump. I am very interested in a solution for this so if anyone is able to help, I will be very grateful :slight_smile: