Prevent the bullets from hitting oneself

When I was firing the bullet, due to the large collision box of my bullet, it immediately collided with the character itself at the moment of firing and hurt myself. However, I didn’t want to simply change the response to collision channel because I needed to attack other characters of the same collision type. May I ask how this kind of problem is solved in regular games?

When you spawn an actor, you can pass an Instigator (Pawn class) or Owner (Actor class) on the Spawn actor node (by expanding it). If C++, you can rely on the functionSetInstigator to set the instigator, I believe. So one option would be to check that the hit actor isn’t the Instigator/Owner of your bullet, before deciding or not to process the hit behavior.

Hey there @beerduckReal! Welcome to the community! So depending on if you’re using Single Trace or Multi Trace, and C++ or Blueprints, there’s multiple ways to handle it.

For Blueprints, there’s Ignore Self Boolean which should ignore the actor that’s creating the cast automatically. If your actor is actually multiple separate actors, you may need to add them to the Actors To Ignore array here:

For C++ it’s mostly the same, but instead of a Boolean to ignore self, you will have to populate the FCollisionQueryParams portion of the trace with actors to ignore.

//Define the FCollisionQueryParams, here I use QueryParams
FCollisionQueryParams QueryParams;

//Then add a self ref to the ignored actors
QueryParams.AddIgnoredActor(this);

//This is an example trace to show where the params go in the function.
    FHitResult HitResult; 
    bool bHit = World->SingleLineTraceByChannel(
        HitResult,       
        TraceStart,       
        TraceEnd,        
        ECC_Visibility,   
        QueryParams       
    );

Hope this helps!