Raycasting fails to avoid owner

UE4 uses a Collision-Trace-Channel system for raycasting (and physical collision). Interestingly, the Collision property is not only applied to “colliders”, but everything with a mesh. In order for the raycasting to work properly, you need to set the Collision property for every mesh component correctly.

To avoid hitting the owner, first create a customized Trace Channel in Project Settings > Collisions > Trace Channels. Then set the Trace Channel to Ignore in the Collision property of each mesh of the owner. In code, the first customized Trace Channel is referenced as ECollisionChannel::ECC_GameTraceChannel1. This is the enum to feed into the LineTraceSingleByChannel function.

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *

The AI Project