Using a Multi Line Trace (Raycast) by Object

This tutorial covers using a Multi Line Trace by Object Blueprint node to return all World Dynamic Actors it hits, and prints their names.

Multi LineTrace For Objects will perform a collision trace along a given line and return all hits encountered, returning only objects that match one of the specified Object Types. Below, you will find steps for setting up a Multi LineTrace For Objects Blueprint.

Steps

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 Multi Line Trace For Objects node and set Draw Debug Type to For One Frame, using drop-down window.

    Copy Node Graph

    01_AddMultiLineTraceForObject.png

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

    Copy Node Graph

    02_AddMakeArray.png

  4. Use the Add pin button to add more Object Types to the Array. Select the WorldDynamic and the PhysicsBody as your Object Types, using the drop-down menu of the Make Array node.

    03_AdjustingMakeArray.png

  5. Drag off the execution out pin of the Multi Line Trace For Objects node, search for and add the For Each Loop node. Connect the Out Hits pin of the Multi Line Trace For Objects node to the Array pin of the For Each Loop node.

    Copy Node Graph

    04_AddForEachLoop.png

    This allows you to do something for each of the Actors hit by the trace.

  6. Drag off the Loop Body pin of the For Each Loop node, search for and add the Print String node.

    Copy Node Graph

    05_AddPrintString.png

  7. Drag off the Array element pin of the For Each Loop node, search for and add the Break Hit Result node.

    Copy Node Graph

    06_AddBreakHitResult.png

  8. 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

    07_BPScriptFinal.png

    This will now print to the screen each of the Actors hit by the array.

  9. Click Compile and Save buttons.

    08_SaveCompileButton.png

Setting the Level

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

    09_SearchCeilingLight.png

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

    10_DragCeilingLight.png

Result

Multi Line Trace For Objects, unlike Multi Line Trace by Channel, does not stop at the first object it hits, which is why the trace continues through the light to the cube.

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