UE4: How to get an actor or surface to change it's material when clicked?

1.6k views Asked by At

I'm having a few questions about UE4. I'd like to have an actor or landscapes material changed, if a specified item is used on it. for example: if i use a hoe on grass, the grass material should be replaced by a dirt material.

My Problem is, how do i get the specific actor or (part of) a landscape i'm hitting?

I'm working with blueprints in ue4 since I've just begun studying. I'm looking for the easiest solution, so i can improve.

1

There are 1 answers

0
JonS On BEST ANSWER

AFAIK you cannot change a landscape material at runtime, unless you do some serious modification to the engine. I would suggest making a dynamic mesh plane and fitting it to the underlying landscape mesh structure, then applying your "hoed" material to it. Still needs a programmer or at least some code experience, though.

As for changing an actor's material - at runtime (in the BeginPlay node), create and store two Dynamic Material Instances. Set one material instance to the actor's default material and immediately apply it to the mesh. Set the other material instance to whatever you need. At the appropriate time, set your actor's mesh material to this second Dynamic Material Instance and voila!