CoderTrevor's Adventures in Deep Rock Galactic Modding

Journey 3: I spy with my little eye...


By the end of this journey, you'll be able to look at almost any actor in the world and see its name, and you'll have an introduction to a very useful form of collision detection in Unreal Engine: line tracing.

You'll also be able to delete any actor your character looks at!



For reference, you can download archives of my project files from before this journey began and after its completion.



There's a saying, "It's a bad carpenter who blames their tools." I never really got that. Maybe the idea is that a good carpenter would invest in better tools? What about poor carpenters who are just starting out? Seems a bit harsh.

At any rate, as mod developers, it's definitely true that we can't blame our tools, because we can make our own tools! To that end, we're going to begin working on a blueprint that let's us inspect some aspects of the game in real time.

To get started, we'll make this blueprint tell us the name of whatever actor the player is looking at.

Part 1: Tracing a line from the camera

To see what we're looking at, we're going to be tying into the physics system and tracing a line beginning at the camera and ending somewhere in the distance. The line will begin at the camera position and the endpoint will be based on the direction the camera is facing.

If you have experience with another engine like Unity, you may know this concept as raycasting. In Unreal Engine, it's called line tracing.
  1. In the AdventurousMod folder, create a new Actor blueprint called BP_ActorInfo and open it for editing.
  2. Right-click on the event graph and add a Get Player Camera Manager node.
  3. Drag off two nodes from this one, Get Camera Location and Get Actor Forward Vector.
  4. Get Actor Forward Vector will return a unit-vector (a vector of length one) which points in the direction the camera is facing. we'll want to look forward far off in the distance, so we're going to multiply this vector by 10,000, which will make it 100m in length (since the units are in cm).

  5. From the Get Actor Forward Vector node, drag off from the Return Value node and type in * in the search bar, and select vector * float.
  6. Type 10000 in the float box.
    BP_ActorInfo 1
  7. We want two points in world-space to define a line. We have one of them (the camera location), and we have a directional vector 100m long. If we just add the camera location to this vector, we'll get the other point.

  8. From the Get Camera Location node, drag off and type + in the search bar. Select vector + vector.
  9. Drag the return value from the X node into the second box of the addition. BP_ActorInfo 2
  10. Now we have the two endpoints to define our line and we can tie into Unreal's pysics system with a line trace.

  11. Right-click on an empty space in the graph and add a new LineTraceByChannel node.
  12. Drag the output of the Get Camera Location node to the Start input of the LineTraceByChannel node.
  13. Drag the output of the vector + vector node to the End input of the LineTraceByChannel node.
  14. We want to do this every frame, so move the Event Tick node over and drag its execute pin to the LineTraceByChannel node. Line Trace setup>
  15. Our graph is started to look a bit messy, so let's clean it up. Here's how I've cleaned mine up, but you can do whatever you think looks the most pleasing. Cleaned-up line trace
  16. There's a lot of ways you can make a graph prettier, like straightening the connections between nodes. Hold shift and select multiple nodes, then right-click on them and select ArrangementStraighten Connections. Or just press q. It makes a difference which node you've selected last. There's also other options under the Arrangement menu; I recommend you play around with them to see what you like best.

    In the screenshot above, I straightened the connection between Get Camera Location and LineTraceByChannel, and aligned the column of nodes in the middle to the right.

Part 2: Doing something with the result

Now we have a way to know what actor the player is looking at, but we need to do some legwork to print info about it on the screen.

The first thing we need is to save a reference to our HUD so we can set the text on it. This should be something you're familiar with by now:

  1. From the BeginPlay event, drag out a new Get Actor of Class node and set the class to BP_AdventurousMod.
  2. Drag off from the Return Value a Get HUD Ref node.
  3. Promote this to a variable named HUD Ref.
    Getting HUD Ref
  4. Collapse the three nodes you just added to clean up the graph.
  5. Now we can use our reference to write to the HUD.

  6. Go back to the LineTraceByChannel node, drag off from Out Hit and create a Break Hit Result node.
  7. Now we can see everything that gets returned to us when a line trace completes. It's a lot! Some of this won't apply to every hit, though. For instance, Hit Bone Name will only have a value if a skeletal mesh was hit.

    We're most-interested in Actor Hit.

  8. From Actor Hit, drag off a Get Display Name node.
  9. Next, drag in a Get HUD Ref node. From there, Drag out Get txtOutput2SetText (Text).
  10. Drag the Return Value from Get Display Name to the In Text input of the SetText (Text) node. This will automatically create a ToText (string) conversion node.
  11. Finally, drag the execution pin from the LineTraceByChannel node to the SetText (Text) node. Getting actor name
  12. Save and compile this blueprint and open the BP_AdventurousMod blueprint.
  13. Drag off from the last SpawnActor node and create a new Spawn Actor from Class node.
  14. Set the class to the new BP_ActorInfo blueprint.
  15. As always, split the Spawn Transform input to set the position and change the collision rules to ignore collisions and always spawn.

  16. Updated BP_AdventurousMod
  17. Compile and save this blueprint and launch the mod.
    screenshot

Run around and take a look at things. This should help you get a better understanding of how things are constructed in the space rig, and might just give you some ideas of what to mod and where to start.

You'll notice that you don't see a description for everything. That's because we're only getting the names of actors, and only when they have collision volumes attached. Still, you can see a lot of stuff!


Part 3: Having some fun with it

This next part isn't useful for modding per se, but it will be fun!

We're going to add the ability to delete any actor by looking at it and pressing delete. All we need is to store a reference to the actor being viewed, and add an event to destroy it when the delete key is pressed.

  1. Critically, we first need to enable our actor to receive input. Go to the Event BeginPlay node; we'll want to add another node after the Get HUD Ref collapsed code.
  2. Oh no! We don't have any execution pin to drag off of from the Get HUD Ref node! We can easily fix that, though.

  3. Select the Get HUD Ref node and look at the Details pane. If you don't have this pane, you can open it by navigating to WindowDetails in the top menu.
  4. Click the + next to Outputs to add a new output.
  5. Name the new output Then and set its type to Exec.
  6. You can name execution inputs execute and execute outputs Then to keep any text from showing up next to the pin.
    Adding execute pin
  7. Next, we need to go into the Get HUD Ref node (double-click on it) and make sure the execution output is connected to the rest of the graph. Otherwise, we'll be stuck with a subtle bug where nothing that comes after that node will be executed, and the reason why won't be obvious.
    Connecting execution pin
  8. Back in the main Event Graph, add an Enable Input node after Get HUD Ref and drag off the Player Controller input into a new Get Player Controller node.
    Enabling player input
    Remember this step and don't forget it! Not just here, but in general. At some point, you will wonder why your blueprint isn't responding to any keypresses, and leaving out this Enable Input node will be the reason.
  9. Next, we'll store a reference to the actor being viewed.

  10. On the Break Hit Result node, Right-click on the Hit Actor output and promote it to a variable called Visible Actor.
  11. Hold alt and click on the execution line going in to the SetText (Text) node to delete it, then insert the Set Visible Actor node into the execution flow.
    Storing Visible Actor
  12. Next, create a Delete keyboard event.
  13. From the Pressed pin, drag out a new Destroy Actor node.
  14. Drag in the Visible Actor reference and set it as the Target of the Destroy Actor node.
    Adding Destroy Actor node
  15. Compile and save the blueprint and hop back into your mod.
  16. Enjoy your new God-like ability to erase almost any item from reality with the press of a key!

Wasn't that fun? You should be starting to appreciate just how much power blueprints give you as a modder!
As we go on, we'll keep improving our tools and understanding of the game, and all of these accomplishments will build on each other and enable us to build increasingly-ambitious mods.