Triggering Events with Line Trace

While focusing on some Blueprint related tasks, I decided to try making a light switch. You walk up to it and look at it, press a key (E in this example), a static mesh rotates (the switch), a sound is played, a light is toggled somewhere in the level. I made this a custom event so I could call it from my character controller. When I replace the custom event with a simple key press, the lightswitch blueprint functions as normal, but I can’t get it to trigger with the character controller script.

I added some extra events to test the Branch and the Cast Failed events, and they always return false or fail the cast. It never succeeds. Even though the debug trace from the camera to the hit point seems to hit the object, but doesn’t get a response. What am I missing? Why is this failing to trigger the second script?

1 Like

Are you sure the trace actually hits the light switch? Did you check if you’ve got any invisible/translucent geometry infront of it? Also keep in mind that if there is close-by object with a rather big collsion volume, the it might get hit instead of your switch. Traces are done against collision volumes by default. And sometimes A sphere volume might extend too far away from the actual mesh it is attached with.

To see if the hit is correct, do this: Instead of trying to cast and call the custom event, call a ‘Destroy Actor’ node and pass the Hit Actor as input. See which actor gets removed from the scene? That way you could confirm the hit is working as intended.

If the trace is not hitting your intended object, check the volumes of nearby objects, and also make sure the collision settings for your switch blueprint is correct. You should at least have ‘Blockall’ for ‘Visibility’ channel. ‘Overlap’ mode does not generate hit events.

1 Like

You are correct, it definitely isn’t hitting the blueprintable object. I noticed the beam actually makes a square when it hits the target. In my case, the laser is shooting right though the light switch, so it’s not blocking anything. I adjusted my view so you can see the laser, but its shooting right through my lightswitch actor. So is there a property on my components that I’m forgetting to change?

In your Switch’es blueprint, make sure you have a collsion component as your root (Capsule, Sphere or Box). Or that your Static mesh has a valid collsion geometry. After that within the ‘Collsion’ settings, set the collsion channel settings so that your object will ‘Block All’ in the visibility channel. OR you can simply set Collsion Behaviour to ‘Block All’. That should fix this.

Thank you. That worked. I knew it was something I had overlooked. My static mesh had no collision, and I didn’t have the collision geometry component as root. I thought it was okay as long as some sort of collision was in the hierarchy, but I guess not. Now I know. Thanks again.

If the issue is solved, mark this thread as solved.
Thanks :wink: