LineTraceSingleByObjectType() returns a bool

To test if the LineTrace hit something or not, one could use the boolean returned by the method
LineTraceSingleByObjectType documentation here

bool Hit = GetWorld()->LineTraceSingleByObjectType(
		OUT HitResult,
		PlayerViewPointLocation,
		LineTraceEnd,
		FCollisionObjectQueryParams(ECollisionChannel::ECC_PhysicsBody),
		TraceParams
	);

	if (Hit)
	{
		FString HitName = HitResult.GetActor()->GetName();
		UE_LOG(LogTemp, Warning, TEXT("We hit: %s"), *HitName);
	}
2 Likes

Thanks for posting this! This will help a lot of students!

Privacy & Terms