Download

LineTraceSingleByChannel doesn't give FHitResult an actor when hitting ABrush

Hello,
I have this code which sends a line trace from my player’s weapon to the place that they are looking. Then I use the OutHit.GetActor() to do some stuff. This works fine for the static meshes and characters in the level but when I added a geometry brush actor and fired at that OutHit.GetActor() returns NULL. I know the line trace hits the stairs because LineTraceSingleByChannel returns true.


if (GetWorld() != NULL)
        {
            APlayerCharacter* playerOwner = Cast<APlayerCharacter>(this->GetOwner());

            if (playerOwner != NULL)
            {
                FHitResult OutHit;
                FVector Start = playerOwner->GetFirstPersonCameraComponent()->GetComponentLocation();

                FVector ForwardVector = playerOwner->GetFirstPersonCameraComponent()->GetForwardVector();
                FVector End = ((ForwardVector * LineTraceLenght) + Start);
                FCollisionQueryParams CollisionParams;
                CollisionParams.AddIgnoredActor(this->GetOwner());
                if (GetWorld()->LineTraceSingleByChannel(OutHit, Start, End, ECC_GameTraceChannel1, CollisionParams))
                {
                    UE_LOG(LogTemp, Warning, TEXT("Hit Somthing"));
                    if (OutHit.GetActor() == NULL)
                    {
                        UE_LOG(LogTemp, Warning, TEXT("Couldnt get the actor"));
                    }
                }
            }
        }

Is there a problem with the line trace or am I supposed too convert the brushes into a static mesh? I would rather not, because apart from the line trace stuff it already does what I need for testing.

Good morning,
I looked at it a little and it’s like the UModelComponent that the LineTrace hit doesn’t have any AActor Owner. I don`t know why it’s like that, but the problem is not on your side.

This is the part where the LineTrace fails to get the actor (CollisionConversions.cpp - 399):


    // Grab actor/component
    if( OwningComponent )
    {
        OutResult.Actor = OwningComponent->GetOwner();
        OutResult.Component = OwningComponent;

        if (bReturnPhysMat)
        {
            // This function returns the single material in all cases other than trimesh or heightfield
            if(PxMaterial* PxMat = PShape->getMaterialFromInternalFaceIndex(FaceIndex))
            {
                OutResult.PhysMaterial = FPhysxUserData::Get<UPhysicalMaterial>(PxMat->userData);
            }
        }
    }

I also tried to find a workaround without having to convert the Brush to a StaticMesh by comparing Tags, Location and Components with all the other Actors in the scene, but no success.
Sadly, I think the easiest solution is to convert them. If you find any alternative, let me know.

Have a nice day!
Alex.