Right approach to change materials of actors by widget

Not sure how useful this is as I do not know how the rest of your setup is hooked up but it could look close to this:

  • actor with a Dynamic Material Instance

  • the material

  • the widget dispatches colours when its button is clicked
  • you could opt to not mix up the colours like I did…

  • this could be in the Pawn or in the Player Controller:

  • create a widget and keep it hidden
  • clicking button widgets checks for valid selected (gripped) object; if so, we apply the appropriate colour
  • LMB simulates Grip; we grab a reference of what’s under the pointing device and store it, or clear it if it’s something undesired
  • show / hide widget depending on validity of the selected object

End result:

Image from Gyazo

You may need to adapt it to you needs.

1 Like

I have a level with 6 objects, they are the same and I want to change colors. So I made a widget that appears on Left Grip when hovering a triggerbox near the objects. What I want is to select an actor and change color by the widget with the controller.

I am a bit stucked now how to set this properly up in an efficient and good way.
Have to say that I am quit new to unreal and learning everyday more…

Any help is welcome.
Thanks in advance!

Forgot to say: I want to change color for each actor individually, so select one and change color and so on…

Thanks for the quick reply!! I will study your suggestions tomorrow and try to implement them into my Bp’s

I have set the most parts in my BP and widget/material, but I am stuck at the end:
See my BP, I can’t connect the Selected_object. I don’t know to what type I have set this param?

Selected_object

This should be of Actor type so it will accept any actor. Right click Hit Actor pin on the Break Hit node and Promote to variable. Or select the variable and change its type manually.

Your bind node needs a reference to the widget - showing an error at the moment.

Thanks. Still no luck to connect the target to Bind event to ED Send Colour. When try to connect selected Actor it gives an error.

I also do not know how to connect the widget to the Set Visibility.
I don’t know if I need these nodes, because I set eralier the visibilty of the widget on my Left Grip?
See earlier attached BP screenshots…

If the goal is to show / hide actor (with a widget component I presume?) you’d do that instead of the widget itself.

You still need to obtain the widget reference for the dispatcher Bind, though - I think we discussed it in the other thread of yours? It was called BP_colourBP or something (or am I mixing things up?)

ColourBP → Get Widget Component → Get User Widget → Cast To (widget class)

Essentially, the goal is for the LB to receive a call from the widget. I have no clue how things are set up in your project and only vaguely remember something about it. Sorry.


What I suggested is a method for moving data across BPs, rather than a plug & play solution. You will need to adapt it to your need.

Thanks again for the reply! What I have to do is simplify things a bit for my solution:

I have set up a LeftGrip event to show my widget, that works fine. The last post we discussed the on hover to close the widget, that works also fine now.

What I want in my case, is change color of a selected actor. I setup the widget buttons and BP and did also for 1 actor I want to test this for.

In my humble opinion (think about I am quite new to unreal) I have only to set up the color change on click button in the widget. I guess thats done om the set vector parameter value on material?

The only thing I can’t remake in my case, is the check that’s the actor is selected and so the colour is applied to that specific actor…

Not really clear for me what w widget (SET) is ?
And how to hook up the variable SelectedActor. When I try to link it to target of Set vectorValue on Material it says: Actor Object reference is not compatible with Mesh component Object reference.

The lower part: I think I don’t need to set visibility of the widget, because I set it already earlier in my level BP to Leftgrip. What part do I still need of these lower nodes?

Not really clear for me what w widget
(SET) is ?

It’s a reference to the created widget. Again, I don’t know your setup so it may not be applicable - this is just a general approach, not a tailored solution to your very project - you should absolutely implement it on your end the way you need it.

My thinking was: rather than having 6 objects each with a separate widget, I’d create only 1; which can then be used to alter the colour of anything interacted with. The reasoning behind it: the memory footprint - 1000 actors each with a widget far exceeds having just 1 widget to rule them all!

Do tell how you’d rather have it work. Each actor owns its widget that changes the looks of owning actor? Can be done. Somehow I don’t feel I’m wrapping my mind around it, though.

When I try to link it to target of Set
vectorValue on Material it says: Actor
Object reference is not compatible
with Mesh component Object reference.

Actors don’t have materials. Actors have components - lights, cameras, widget components, static meshes… When we’re talking about materials, we’re talking about one of the component’s materials. One actor can have many static meshes (think a modular car), each static mesh can have multiple materials, too.

If you tell the editor to change materials of the actor (Actor Object reference is not compatible with Mesh component Object reference), it will make little sense. The editor does not know which component of the actor to apply the material to.

You said you wanted to:

Right approach to change materials of
actors by widget

I believe is that what you really wanted is to change the look of one of the components - I assumed a static mesh as this is the most common scenario.

The only thing I can’t remake in my
case, is the check that’s the actor is
selected and so the colour is applied
to that specific actor…

That’s what the Selected Object does. It stores a reference to the last object you interacted with, providing it was of the desired type - Cast To. If undesired, type is clicked, the cast fails, the reference variable is set to none, cleared.

Not sure how useful it’d be but here’s the zipped project:

Thanks for all the explenations and patience!!

I have set up the nodes in my project, but 1 thing is not working: What do I have to set as target at the BindEvent ED Send Colour? If I refer to my widget, it gives an error while playing. Do I have something attached to it refering the widget for interactions?

My widget is placed in an actor, maybe it has to do something with that?

What do I have to set as target at
the BindEvent ED Send Colour?


My widget is placed in an actor, maybe
it has to do something with that?

So an actor has a widget component that owns the widget that changes colours. Got it. As above then:

ColourBP → Get Widget Component →
Get User Widget → Cast To (widget
class) - that’s the widget.

For a LB actor dispatching data from its widget embedded in a component, I’d:

Now every time that dispatcher is called (by a widget button click, perhaps), the event in the LB will trigger. If you use Assign, you’ll get the correct signature, since these can get complicated:

Image from Gyazo


Do note that blueprints are context sensitive, it almost never pays off to plop down nodes just like that. Drag a wire first and then search for things. Otherwise it’s rather easy to get lost as the naming conventions in Unreal are far from ideal…

For example, half the time Material Instance Dynamic is called Dynamic Material Instance - both in the docs and in the engine…

ok thanks, I set that. Things are really messed up right now. The close button of the post yoy answered ealier isn’t working any more.

I get a yellow ! explenation mark in the comiling of the widget. It’s a eventdispatcher I made earlier with the wrong name, but it still remains in the widget BP. I can’t delete it!
Nor do I see it at the Event Dispatchers list.

Is that maybe a problem? How can I delete this graph node?

I now restore a backup of the working state, without the adjustments made in this post and start from scratch this topic again… Come back later…

I have tried some things. The close button of the widget is working again.
I set up the LB and the color picker widget. It doesn’t work yet, but maybe I am working in the wrong direction? Or missing some crucial nodes?