Download

LineTrace on client returns ignored actor in HitResult

In my game, I’m performing line traces to figure out if a weapon has collided with an enemy during combat. The swing of the weapon can sometimes intersect the user, so I am ignoring the user actor to ensure the player can’t hit themselves!

The logic looks a little like this:



FCollisionQueryParams query(FName(TEXT("DamageHitBox Swing")), true, GetOwner());
query.bTraceComplex = true;
query.bReturnPhysicalMaterial = true;

//Ignore Actors
query.AddIgnoredActor(Wielder);
query.AddIgnoredActor(GetOwner());

if (GetWorld()->LineTraceSingleByChannel(hitData, TraceStart, TraceEnd, ECollisionChannel::ECC_GameTraceChannel4, query))
{
          ACharacter* hitCharacter = Cast<ACharacter>(hitData.GetActor());
          UDamageHitBox* hitBox = Cast<UDamageHitBox>(hitData.GetComponent());

          if (hitCharacter)
          {
                     if (hitCharacter != Wielder && hitCharacter != GetOwner())
                     {
                              ProcessHitCharacter(hitCharacter, hitBox);
                     }
           }
}


This has been simplified a little but shows the general gist. “Wielder” is a pointer to the character that owns the weapon which is being swung.

I have made it so that this logic only runs if the Wielder is locally controlled, and then the “ProcessHit” function is run on the server.

When run from the server, this code works fine, the player can swing the weapon and never hit themselves. The problem is when it is run from the client - the player swinging can hit themselves and deal damage to themselves. Strangely, it appears to think that the Wielder is not equal to the hitCharacter, despite them being the same actor. Here’s a quick view in debug:

As can be seen, they’re both the same character, but strangely have different memory locations. I can pass either through to the Process function, and it will always effect the same character, regardless of which pointer is used.

Is there a better way of checking actor equality? Why does it think these are two different objects?