Sphere trace sometimes result in hit but the Actor hit is null

I’m doing a sphere trace, and sometimes it happens that the trace results in a hit, but the Actor hit doesn’t actually exists.

The code looks like this:



    FHitResult sphereTraceHitResult;

    bool sphereTraceHit = GetWorld()->SweepSingleByChannel(sphereTraceHitResult, rayStart, rayEnd, FQuat(), ECollisionChannel::ECC_Visibility, FCollisionShape::MakeSphere(5), QueryParams);

    if(sphereTraceHit)
    {
        AActor *hitActor = pHitResult.Actor.Get();

        // Sometimes this prints 1, meaning that the actor is NULL
        UE_LOG(LogTemp, Warning, TEXT("hitActor is NULL: %d"), hitActor == nullptr);
    }


I don’t understand why this is happening. If there is a hit, shouldn’t there ALWAYS be a hit actor?

Are you checking the right hit result?
You’re passing sphereTraceHitResult into SweepSingleByChannel but looking for the hit result in pHitResult.

**** copy and paste! I don’t know how I didn’t see that. In my situation it was “hidden” so well that during gameplay the issue only came up a few times, so it wasn’t that clear; but still, I should’ve seen it in the code. Thanks a lot!