Pluses and minuses of course, this approach means less duplication and is mentioned by Ben
FVector playerViewPointLocation;
FRotator playerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(
OUT playerViewPointLocation,
OUT playerViewPointRotation
);
FVector directionVector = playerViewPointRotation.Vector() * reach;
FVector lineTraceEnd = playerViewPointLocation + directionVector;
return LineBeginningAndEnd(playerViewPointLocation, lineTraceEnd);
where
typedef std::pair<FVector, FVector> LineBeginningAndEnd;
Also this approach of condition and assignment at the same time:
if (AActor* hitActor = hit.GetActor())
{
UE_LOG(LogTemp, Warning, TEXT("The struck actor is %s"), *(hitActor->GetName()));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("No Actor struck"));
}