I’m having a ton of issues with line tracing, and have read up on documentation but am still coming up short.
Essentially, I am looking to “place” items in my world. An object is created hovering above the ground, and I’m trying to cast a line from here vertically downwards - hoping to hit any object with the “PlaceSurface” type. This is important, as I don’t want to be able to place objects on other players for example, and it constrains my gameplay in the way I would like.
The following is the code I’m using to create the trace:
FHitResult HitResult(ForceInit);
FCollisionQueryParams TraceParams = FCollisionQueryParams(FName(TEXT("PlaceVerticalTrace")), true);
GetWorld()->DebugDrawTraceTag = FName(TEXT("PlaceVerticalTrace"));
TraceParams.AddIgnoredActor(GetOwner()); // The player pawn
TraceParams.AddIgnoredActor(PlacingActor); // The object I'm placing
// Cast from placing actor to floor
// This is just the placing actor's position with 2 offsets
FVector TraceStart = FVector(DirectionVector.X, DirectionVector.Y, 100.f);
FVector TraceEnd = FVector(DirectionVector.X, DirectionVector.Y, -10000.f);
// I'm using a LineTraceSingleByProfile here, but I've also tried by channel, by object - both to no avail.
bool bIsHit = GetWorld()->LineTraceSingleByProfile(HitResult, TraceStart, TraceEnd, FName("PlaceSurface"), TraceParams);
if (bIsHit)
{
DrawDebugSphere(GetWorld(), HitResult.Location, 2.f, 8, FColor::Green, false, -1, 0, 1);
}
The blue line here shows the debug trace result, it is being cast where I expect, but the floor is not being hit. Here are some screenshots of the collision settings on my floor:
And finally the profile itself:
I would appreciate any thoughts, questions, comments to help my understanding here! Thanks.