Change material if a line trace hit an actor, and revert back to the original material if it didn't hit the actor

Hi there

I’m a bit rusty after taking a short holiday break from toying around with UE4. I wanted to have the material for a specific actor change every time it is in the player’s sights. The material would then revert to the original one when not looking at it.

I can’t really use a cast as I need two output (when the line trace hits the actor, and when it doesn’t) and making a reference in the character’s blueprint will only allow me to have this system work on only one actor (I have 3 copies of this actor as of right now).

I’m starting to wonder if using a collision instead would work better here or not.

Any advice is appreciated, thanks.l

Using collision for this would work fine but if you want to stick to tracing, consider storing the previously hit actor and flip its texture back as soon as the new trace is valid. Something like this should work:

I tested it for the entire 7 seconds so tread with caution…

https://gyazo.com/dea8615631264d775299fe4f7c21d97a

Every tile up there is a separate actor.

Thank you! Didn’t know you could do a verified get, that’s probably what was bugging me off a bit.

Alternatively, you can do normal Get followed by IsValid - but that’s lots of nodes and wires. Good luck!