How to ignore actor class with line trace in C++?

Here is my current situation:

I have an instant-fire weapon which sends a trace for each shot. I have added a bullet tracer actor which acts as a bullet tracer effect (has a particle effect attached to it). The bullet tracer actor is created at the same time the line trace is made. This results in the trace hitting this bullet tracer actor.

How can I prevent this from happening?

#Collision Channels

You can use custom collision channels, create a trace channel called “weapon trace”

Create a BP for your tracer bullet and customize the collision on the mesh and tell it to ignore “Weapon Trace”

This is all done in the editor itself.

I am writing a book UE4 C++ that will explain all this in more detail

Rama

1 Like

Thanks, this works perfectly.

Rama,

What’s the planned release date for this book you’re writing ?

If you want to ignore a specific instance of an actor you just have to add it in the CollisionParams object. For example if you want to ignore the Actor Player when doing a LineTrace:

   FCollisionQueryParams CollisionParams;
   CollisionParams.AddIgnoredActor(Player);

    World->LineTraceSingleByChannel(OutHit, StartLoc, EndLoc, ECollisionChannel::ECC_WorldStatic, CollisionParams);

Hope this helps.

.

2 Likes