Line trace collision not working when out of camera

Hi everyone, I create a friend-AI character from an enemy-AI character, so they can melee attack each other(line trace for collision handle), everything is fine when the camera(from the controlled player) is toward them, but when the camera is backward(can’t see the two characters), the two characters still melee attack each other, but the attack collisions don’t happen, until the camera is toward them again. Is line trace invalid if it’s out of camera? Can anyone give me a hint? Thanks a lot.

I guess it is the forward vector from the camera that needs to be towards the other character.

In fact the line trace is from friend-AI character to enemy-AI character (or from enemy to friend), the controlled player is just an observer, so the line trace isn’t from the camera. But when the camera is toward them, the line trace works fine, when the camera turns back, the line trace doesn’t work, very odd bug :frowning:

I got the same problem with my AI, when I turn the camera the linetrace stop being cast, still trying to figure out a workaround. Tried running the linetrace from a function into the game instance and then the game mode but then the lines never appear even if the camera is looking

Have you found a solution for this problem?
I’m facing the same problem.

Is the trace logic triggered by something animation based?
If so, skeletal mesh components have an optimization setting called “Visibility Based Anim Tick Option” where you can set it to not update when it’s not visible, so make sure it’s not set to “only tick when rendered”

I have the exact same problem, I have set an enemy AI that uses tracing on its mesh when attacking to trigger a “deal damage” event but it doesn’t work when the tracing itself is out of camera. It’s a huge problem since my prototype is in first person. So I can just stand there, having an enemy attack my back and it won’t trigger any event. If I switch to the debug camera and see the enemy and the tracing, the event triggers again. If I look away with the debug camera, it stops triggering.

I wish I had known that before building a combat system on traces…

If the camera is inside the character, are you ignoring the character’s own meshes for the trace? Mentions it toward the end here.

Traces in Unreal Engine - Overview | Unreal Engine 5.1 Documentation

I can give C++ exampe for that but no clue how to do it in BP.

What is ignored or not for the trace is irrelevant. As long as the trace is not happening on camera it’s not rendered and it doesn’t return anything.

Are you drawing the line in space? For debugging traces I draw the line, then eject from the game, and see where it is.

DrawDebugLine | Unreal Engine Documentation