Disable Input when raycast is not hitting Interactive object

I create a ray. And when the ray hits the lamp it will show a message saying “press f” to turn on/off.

So I create a ray that when it his the lamp it will enable input so I can press “f” to turn on/off the lamp.

Its working

BUT even when the ray is no longer hitting the lamp, I can still press “f” to turn on/off.

I want it that I can only press “f” to turn on/off the lamp ONLY when ever the ray is hitting the lamp.

Heres my lamp

ive posted the same issue but its not really clear and I got very confusing node graph.
but I do appreciate that guy who took time responding, hes awesome! one day I’ll understand his answer xD

When you shoot your ray out into the world, you want to get the actor which it hits, then cast it to the light you have. If the cast succeeds, you can store a reference to that actor within your character object. If the cast fails, you just clear out the reference value.

When someone presses the “F” key, you want to place an “Is Valid” node which checks the reference. If its valid, you can call some sort of “interact” method on it. If its not valid, you do nothing.

Architecturally, I’d either create a base class/blueprint which all of your various light switch types inherit from and create a “Interact” method. Each blueprint which inherits from this base class should override the “interact” method and turn on/off any blueprint components (such as point lights).

Alternatively, you can use the blueprint interfaces (See: Content Examples, Level “Blueprint Communication”, Section 3.2) to do the same thing.

thanks for the response again. I’m already using blueprint interfaces that event node on the graph. Now you mention about clearing reference value Ive been looking on this in the ue4 docs and wiki. can you explain how to do this? and what node to use to clear reference?

Oh I think Ive already figured it out ;D but I’m not sure if what I did is an efficient way of doin it. hehe, but its already workin :slight_smile: