Line tracing is used to find objects in a line (find any objects that are in the line of point a to point b). For example, if I line trace from where I am to 20 feet in front of me, I will find a few things, for example a computer.

To do this in unreal engine, it is not too hard. I am going to use the third person template project, and make it so when I click, it prints a string with the object it hits first.

First, open your third person character blueprint. Add the left mouse button node. Then add the GetActorLocation node, and from the return value search for + and select vector + vector. Below that, search for GetRotation. From that node, look for get forward vector. Multiply that by a float of about 1500. Make the return value of that connect to the vector + vector node from before. It should look like this:

From the left click node from before, make the line trace for objects node and plug in the getactorlocation node into the start, and the return value of the + node form before into the end. In the object type input, promote that to a variable. Compile the blueprint, then select “world static” on the right panel for that variable default value. From the on hit output, pick break hit result. Press the down arrow on that node, and from the hit actor output, get to string. From that, print string. Hook the print string to the line trace for objects as well. The code should look like this:

That’s all! now when you start your game, and click, it should print a string with the name of the object. This project was made in Unreal Engine 4.25. Get source code here:

Leave a Reply

Your email address will not be published. Required fields are marked *

coppyright 2020 The Unreal Cousinzzz