Beginner - How to change material of an object by clicking another object

Hi All,

I have just started learning Unreal. I want to build an little app for my science project, but I have absolutely no background in programming or blueprints, so my question is very basic.

I am just trying to change the material of an object by clicking another object, as simple as that…Any help will be very welcomed :slight_smile:

Thanks!
L

There’s an event called ActorOnClicked, if you add that to the object you want to click you can call any functionality you want to happen from there. Since you want to change the material of another object you’ll need to store a reference of that object on the one you want to click and call a function to change the material on the object you want to change the material. I also recommend passing a material reference so if you were to have multiple objects you clicked they could all change the object to a different material rather than a fixed material change.

Had an opportunity to throw together an example for you here. The node you’re looking for is Create Dynamic Material Instance. You can then set the material on the actor you’re interested in.

In order to track this via a click, we need to monitor where your cursor is every tick. When the system detects you’ve hit a component, we store that in a variable, which can then be used to change the material on click.

Hope that helps!