Download

Facing issues with LineTraceSingleByChannel

I’m pretty new with Unreal4 using c++ and I have an issue with LineTraceSingleByChannel.
I have a basic level (the default level that Unreal provide with the default floor, camera…) I created the project empty in C++.
I also have an actor called card with an static mesh (with collision) which basically is a box with a basic collision.
I have the camera on the top and 3 of these cards above the floor.

I’m using the next code to send a raytrace from the player controller to the floor and try to hit on those cards

FVector Start, Dir, End;
playerControl->DeprojectMousePositionToWorld(Start, Dir);
End = Start + (Dir * 8000.0f);

FHitResult hit;

UWorld* cWorld = GetWorld();
if (cWorld)
{
cWorld->LineTraceSingleByChannel(hit, Start, End, ECC_Visibility);

if (hit.Actor.IsValid())
{       
    ACardActor* hitCard = Cast<ACardActor>(hit.Actor.Get());
        if (hitCard)
        {
            hitCard->Highlight(true);
        }
    }

}

The LineTraceSingleByChannel seems to work but it’s only hitting the floor and not my Cards.
As I don’t have much experience with UE4 using C++, I took the puzzle template that UE4 provides and build my minigame from it. So my code and most of the settings are similar of this template, but I’m building everything from scratch.

I don’t know what I’m doing wrong. Any help?

Is the cards collision set to “Visibility”?
Is the cards collision box non-zero extent? (has actual volume)