Shorter version of using LineTraceSingleByChannel

the function LineTraceSingleByChannel return true if we hit an object.
is it better to use the return value of this function in the “if” statement and not declare another variable?

FHitResult Hit;
if (GetWorld()->LineTraceSingleByChannel(Hit, Location, End, ECollisionChannel::ECC_GameTraceChannel1))
{
	DrawDebugPoint(GetWorld(), Hit.Location, 20, FColor::Red, true);
}

It is not better, no. It’s arguably less readable and the compiler should optimise away the variable anyway.

Always write for clarity unless you have a good reason not to.

thank you,
noted

Privacy & Terms