Using return bool form LineTraceSingleByObjectType()

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()));
	}
}

I don’t think that is would be possible to have an actor hit but not return true. I know the alternative is possible (successful hit but no actor) as someone in the community has experienced that.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms