Came up with this while working on the challenge:
FHitResult Hit;
bool GotHit = GetWorld()->LineTraceSingleByObjectType(
OUT Hit,
PlayerViewPointLocation,
LineTraceEnd,
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
TraceParameters
);
// See what we hit
if (GotHit) {
FString ActorName = Hit.GetActor()->GetName();
UE_LOG(LogTemp, Warning, TEXT("Actor Hit: %s"), *ActorName);
}
Because LineTraceSingleByObjectType() returns boolean when hit was performed, and we only need to grab actor and it’s name when the actual hit happened, I feel that this is slightly more efficient solution. THoughts?