This is how I did it in a FPS game (C++ but should be easy to translate to BP if you’re using BP)
Range is just a float for how far I want to do the trace, can be anything you want
const FVector cameraForwardV = playerController->PlayerCameraManager->GetActorForwardVector();
const FVector cameraLocation = playerController->PlayerCameraManager->GetCameraLocation();
FVector traceEnd = cameraLocation + cameraForwardV * Range;
FCollisionQueryParams params = FCollisionQueryParams::DefaultQueryParam;
FHitResult m_calculatedhit;
GetWorld()->LineTraceSingleByChannel(m_calculatedHit, source, traceEnd, ECC_Visibility, params);
The structure of m_calculated hit will have all the info you need:
- what object was hit
- where the hit occured
- etc.