From Sven, 11 Years ago, written in KLone with C++.
Embed
  1. void ABelovedPlayerController::LineTrace()
  2. {
  3.         // get camera position and rotation
  4.         this->GetPlayerViewPoint(this->cameraPos, this->cameraRot);
  5.  
  6.         // set up information for the linetrace
  7.         const FVector StartPosTrace = cameraPos;
  8.         const FVector EndPosTrace = StartPosTrace + (cameraRot.Vector() * traceLength); // start + direction * lenght
  9.  
  10.         // perform linetracing to get hit information
  11.         FHitResult hitResult(ForceInit);
  12.         GetWorld()->LineTraceSingle(hitResult, StartPosTrace, EndPosTrace, ECC_Camera, this->traceParams);
  13.  
  14.         // cast of the object in hitResult to an IInteractable and store it, if cast is successful
  15.         ABelovedPictureFrame* const pEOObject = Cast<ABelovedPictureFrame>(hitResult.GetActor());
  16.         if (pEOObject)
  17.         {
  18.                 pInteractObject = pEOObject;
  19.                 GEngine->AddOnScreenDebugMessage(0, 2, FColor::Green, "Interactable Object Found!");
  20.         }              
  21.         else
  22.                 pInteractObject = NULL;
  23. }