Raycast problem

Hello, I’m new to unreal, so sorry for the dumb question.

I’m using LineTraceSingle with a custom GameTraceChannel that is blocked by “BlockAll” preset.

FVector End = PlayerLoc + PlayerRot.Vector() * MaxRange;
OwnerController->GetPlayerViewPoint(PlayerLoc, PlayerRot);

FHitResult hit;
bool isSuccess = GetWorld()->LineTraceSingleByChannel(hit, PlayerLoc, End, ECollisionChannel::ECC_GameTraceChannel1); 
DrawDebugLine(GetWorld(), PlayerLoc, End, FColor::Red, true, 2.0f);

Now, when I use this on a wall, IsSuccess is false. The wall has a simple collision shape in the mesh, and here you can see the other details:

What am I doing wrong?

Does your debug line render correctly? Looks like you may need to swap the two lines I quote above as PlayerLoc and PlayerRot wont be set when you use them to calculate End.

Otherwise, try using ECC_Visibility to see if it’s an issue with your collision setup.

May not make a difference in this situation, as it should give a blocking hit if you hit the player actor, but to eliminate this you could add:

FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(GetOwner());
...
GetWorld()->LineTraceSingleByChannel(hit, PlayerLoc, End, ECollisionChannel::ECC_GameTraceChannel1, QueryParams);
1 Like