Using a Single Line Trace (Raycast) by Object

This how-to guide covers using a Single Line Trace by Object Blueprint node to return the first World Dynamic Actor it hits, and prints its name.

Line Trace For Objects will perform a collision trace along a given line and return the first Object the trace hits that matches one of the specified Object Types. To set up a Line Trace For Objects Blueprint, do the following:


Implementing the Blueprint Script

  1. Follow the steps in the tutorial Line Trace By Channel.

  2. Replace the Line Trace By Channel node with the Line Trace For Objects node and set Draw Debug Type to For One Frame, using drop-down window.

    Copy Node Graph


  3. Drag off the Object Types pin of the Line Trace For Objects node, search for and add the Make Array node.

    Copy Node Graph


  4. Specify the Object Type you want to trace for, using the drop-down menu of the Make Array node.


    In this case, tracing are adjusted for World Dynamic Objects. You can add more by clicking the Add Pin button.

  5. Drag off the execution out pin of the Line Trace For Object node, search for and add the Print String node.

    Copy Node Graph


  6. Drag off the Out Hit pin of the Line Trace For Object node, search for and add the Break Hit Result node.

    Copy Node Graph


  7. Connect the Hit Actor pin of the Break Hit Result node to the In String pin of the Print String node. Your script should look as following.

    Copy Node Graph


  8. Click Compile and Save buttons.


Setting the Level

  1. Navigate to the Content folder in the Content Browser, search for CeilingLight Asset, using the search field.


  2. Drag off CeilingLight into the Level, like shown below.



Only the Dynamic Actor returns as a hit with this set up. Consequently, the cubes do not return a hit, since they are Static Actors. You can change Actors type that returns as a hit, by specifying the ObjectType in the Make Array node of the BP_FirstPersonCharacter Blueprint. See 4th step of the Implementing the Blueprint Script.

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey