Component detect being hit with Line trace?

Hey guys,

So this is a pretty straight forward problem from what I can see.
I have a line trace working properly, however I am trying to set up an event in a button blueprint that activates when it senses it is hit by a line trace.

I am doing it this way as I had the button working with a cast from line trace inside the player blueprint however now would like to keep the interaction event seperate from the player blueprint as I intend to have a lot of interactive objects in the world.

So far I have tried Event Hit, Component overlap, and Mouse Overlap, none of which seem to detect the line trace.

Is there a way to get the object to detect being hit by a line trace, or is there a better way of doing this?
Any help at all is appreciated!!

Thank youuu!

1 Like


What I would recommend would be to create a custom event inside of your button blueprint that handles the logic that you would like to use when the button is hit with a line trace. Then, in your character, drag off of the Hit Actor pin of the hit result from the line trace, cast it to your button blueprint, and call your custom event. While some of the logic will still be handled in your character, the event itself is set up inside of your button blueprint.

Here is a screenshot of what I am referring to:

Let me know if you have any further questions.

Have a great day

I’m a little confused as to how I can use this on a large scale with many buttons. Say I have 10 buttons in the level, does this mean I need to have 10 unique casts from the player going to 10 unique button blueprints? Or is there a way I can avoid that?
Thanks so much for the quick answer though!

If you have 10 buttons, are they all based on the same blueprint?

I am also wondering how to do this, I am trying to make an elevator with buttons, but when I do it as you displayed in the image above it detects a hit as one to the blueprint and not a specific component.

Try pulling off of the Hit Component pin that can be seen on the Break Hit Result node in my above screenshot. This should return the component that was hit by the trace rather than the actor itself.

Whenever I try to drag off of hit component, nothing seems to work… It won’t let me connect it to any components

Like the other post I would recommend pulling from the “Hit actor” output. I would cast to a “MasterButton” blueprint that would have a function “Activate” inside of it. You could then make several child blueprint that override the “Activate” function to do different things. This can be accessed in the child blueprint by selecting the “override” dropdown that appears when you mouse over the “functions” section.

Another method of detecting what component has been hit without relying on a child actor setup:

To expand on Sean L’s answer and solve MrGoatsy’s answer I would create a Blueprint Interface with a function and Actor Component Input variable. Compile and save.

Go to your button blueprint and implement the interface using Class Settings. Compile, save and add that event to the graph. Using the component variable you’re able to search by Get Display Name and then build a switch case based on the component name.

Don’t forget to hook up the Hit Component break hit result on your line trace to the Interface event you created.

This way you’re able to reference meshes without further assignment.

i attached an invisible component to my character’s hand, So when reaching for the button the invisible component is SetWorldLocation to the BreakHitResult ImpactPoint overlapping the button, The button can then detect the overlap.

1 Like

i am trying to do the same but the other way around.
i need the object to know when it’s no longer being hit by a line trace.
i have objects that i highlight their outline when looked at, that’s easily done with a line trace when a line trace hits an object call the appropriate event, now here’s the kicker, when i am no longer looking at the object i need it to be unhighlighted, when i am not looking at the object the line trace isn’t hitting it so i no longer have a reference to it.
so i need the object itself to know when it’s being hit by a line trace that way i can also manage to make it know when it’s no longer being hit by a line trace.
tried playing around with two variables idea “current object” and “previous object” but i didn’t get it to work as intended, it kinda works but sometimes gets confused and confuses me with it when alternating between the two too fast.

in here i am inspecting a body with body parts that can be highlighted, “open on” and “close off” events are the Highlight and unhighlight events, since i am building up on horror engine i figure why not use and already made events instead of making different one.

and this is the body part class that’s being highlighted

and here is a video of the problem i am facing

Try this node in the actor being hit by the trace. If the delay completes, means it was not re triggered.

1 Like

No do not cast from line traces. Read up on interfaces.

You need to check if the ray hit an object that implents an interface (nide does implement interface). If it does, then call the interface function e g. Interact on the hit actor / component.

The actor or component that implements the interface will then have its “interact” function called via the interface and do what it needs to.

1 Like

duuuuuuuuude i can’t thank you enough.
i don’t know why i didn’t think of this, this’ll actually solve 3 problems i am facing in two different projects and make things so much easier.

1 Like