Hi, I used the bool return value from the function LineTraceSingleByObjectType() to test whether I had a valid Actor in the FHitResult. Is this overkill or not?
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
FVector Location;
FRotator Rotation;
GetOwner()->GetActorEyesViewPoint(OUT Location, OUT Rotation);
FVector LineTraceEnd = Location + (Rotation.Vector() * Reach);
DrawDebugLine(GetWorld(), Location, LineTraceEnd, FColor(255,0,0), false, -1.0f, '\000', 8.0f);
FCollisionQueryParams TraceParams(FName(TEXT("")), false, GetOwner());
FHitResult Hit;
bool bHit = GetWorld()->LineTraceSingleByObjectType(
OUT Hit,
Location,
LineTraceEnd,
FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
TraceParams
);
AActor* ActorHit = Hit.GetActor();
if (bHit && ActorHit)
{
UE_LOG(LogTemp, Warning, TEXT("Hit Actor: %s"), *(ActorHit->GetName()));
}
}