Download

Have BP triggering event when object is looked at - turn it off again?

Sorry the title is phrased a bit weird, the character limit hindered me a bit.

I’m getting started with doing my own thing in BP and to test something I’ve made a cube actor which I can switch the material for. I tested it with an input key so I know that part works. Now I want to change the material when I look at (point the camera at) the object, then switch it back when I look away.

I set up a trace on the player camera, collected the hit actor from the output, cast it to my BP class and called the “looked at” function.

First question, how do I get the option to pick a custom event in here? I was able to make a copy of the “looked at” function in the level BP and copied it, but couldn’t make on in another actor’s BP in the same way? I figure it must be possible since I could cheat like that, but it seems odd it wasn’t just the same.

Anyway, I have it now that when the camera points at the actor the first time the material changes, permanently. So now I want a way to trigger the actor’s BP event to switch the material back. How should I be doing that? It seems tricky from the character BP as the trace will no longer be referencing the actor since we’re looking at something else, and I don’t think I can trigger anything off of “cast failed” since it’s possible to go straight from looking at one instance of the actor to another. I figure I can fix it that in the box class the “not looked at” event can be triggered when the “looked at” one is not.

Graph is getting a bit messy whilst I try to sort this, so advice would be appreciated.

Hello,
To have access to a custom event / function / variable.
If you are in the same blueprint, you just have to drag it in your event graph.
If you are not in the same blueprint, you need a reference (a cast to / interface / event dispatcher or a variable of the blueprint (the one in the level with which you interact, not a generic one)

For your event : As you talk about mouse, have you try the cursor over events ? (you need to have mouse visible and over / click events activated) You can have them on your actor or on a component.

If for some reason you can’t / won’t use mouse cursor and you use your line trace, create two variables “item hovered” and “last item hovered”. on hit event, when you hover, Store “last item hovered” with “item hovered” and store the item hovered in " item hovered". Then you can set your materials in both new hovered and last one.