CoderTrevor's Adventures in Deep Rock Galactic Modding

Journey 1: Where am I?


By the end of this journey, you'll be able to see your character's position in the world.

You'll also add some features to the HUD which will help you to develop the rest of your mod, and you'll be able to see the HUD in caves, which if you followed the guide on mod.io, you may have noticed doesn't work out of the box.



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



Part 1: Revisiting the HUD

I think I've mentioned before that you should have followed the blueprinting guide on mod.io before coming here.

Let's start this journey off with a quick review:

  1. Create a folder in the Content folder named after your mod. I'll refer to it as AdventurousMod here but substitute "AdventurousMod" with whatever you want throughout these adventures.
  2. In the AdventurousMod folder, create an actor blueprint called BP_AdventurousMod.
  3. Create a HUD widget called WBP_AdventurousModHUD.
    Your project folders should look like this
  4. Add a few lines of text to the left side of the screen and assign them each variables, called txtOutput1, txtOutput2, and txtOutput3. Screenshot of WBP_AdventurousModHUD
  5. Open up BP_AdventurousMod and edit the blueprint so it displays the HUD when the game begins. Save a reference to the widget as HUD Ref. Blueprint to spawn HUD widget
  6. Go back to the Content folder and create the InitSpacerig actor blueprint.
    Create the InitSpacerig actor
  7. Open the InitSpacerig blueprint and make it spawn an instance of your mod.
    Spawning you mod
  8. Build and launch your mod and you should see the HUD:

This should have been a review for you, so hopefully it was easy for you to follow along.

Part 2: Updating text on the HUD and keeping the blueprint tidy

Now, we can use this handy HUD to display information for our own benefit as we develop our mod.

Programming tradition dictates that every journey begins with printing "Hello World." Who am I to break with tradition?

  1. Open the BP_AdventurousMod blueprint and add some nodes to set the text of each text block:
    Setting text on HUD
  2. If you compile this blueprint and launch your mod, you should see the updated text:
    Hello whale pipers!
  3. Now zoom out to view the entire blueprint: An overly-complicated blueprint
    Isn't it starting to look a little... big? I mean it's only really doing two things, creating the HUD and setting some text, but look how complicated it looks!
  4. One thing we could do is add comments. Drag-select the blocks on the left related to HUD-creation, and press c. Then, type "Create HUD."
  5. Next, select the boxes on the right and add the comment "Print Hello Whale Piper."
    Commented blueprint
    That solves the issue of the complexity; now we can see at a glance that this blueprint is only doing two things, and we don't need to think about it any further unless we want to change one of those behaviors. Comments are great, and you should use them liberally. However, we haven't really addressed how needlessly big this blueprint has become. We can do better!
  6. Delete the two comments you just created (sorry).
  7. Again, drag-select the boxes related to HUD creation, only this time, right-click on one of the boxes and select "Collapse to Macro."
  8. Name your new macro "Create HUD."
  9. Repeat this process for the boxes on the right and name the macro 'Print "Hello Whale Piper"'
  10. These didn't really have to be macros. You could have selected "collapse nodes" and accomplished roughly the same thing. You could have also collapsed them to functions. We'll learn more about the differences between these three options later.

  11. Tighten up the node placement and bask in the glory of your super-clean blueprint:
    A beautiful blueprint
As you work with blueprints, you'll find that they become messy very easily, and you may be tempted to leave them this way. Don't. Fight the entropy! Taking a little bit of time to keep your code clean will make working with it easier and more enjoyable, and you'll get more done.

You may have noticed the code in the Print "Hello Whale Piper" macro seems very repetive. We'll address that in a later journey.

Part 3: Printing the player's position

If you've made it this far, you're probably eager to actually have something interesting happen! Let's do that now:

  1. Open the AdventurousMod folder and create a blueprint for a new actor called BP_PlayerPosition. Open this blueprint.
  2. Add a Get Local Player Character node and promote the output to a variable called Player Character Ref. Drag out from the BeginPlay event to set the reference on script execution.
    Storing reference to Player Character
  3. We also need to get a reference to our mod's actor. Add a Get Actor of Class node, set BP_AdventurousMod for the class, and promote the output to a variable named AdventurousMod Ref. Have this node execute after setting Player Character Ref.
    Storing reference to our mod
  4. Drag in a new get for your Player Character Ref near the Event Tick node and drag off a node called GetActorLocation.
    Get Player Location
  5. Now, drag in your reference to the BP_AdventurousMod actor. From here, drag out the following chain of nodes: HUD RefGet Txt Output 1SetText. Begin wiring Set Text
  6. Next, wire up the Return Value of GetActorLocation to the In Text of the SetText (Text) node. You'll notice that this will automatically insert a node to convert the vector to a Text object. Cool!
  7. We want the player's position on screen to be updated every frame, so drag the execution pin of Event Tick to that of SetText. The whole blueprint should now look like this: Final BP_PlayerPosition blueprint
    We're now done with this blueprint. Don't forget to compile and save it.
  8. Just one more thing: we need to spawn an actor for our new blueprint! Open up the BP_AdventurousMod blueprint.
  9. Go to the blueprint's Event Graph and delete the Print "Hello Whale Piper" node.
  10. Drag the execution pin off the Create HUD macro and add a Spawn Actor from Class node. Set the class to BP_PlayerPosition.
    Spawning BP_PlayerPosition
  11. That's enough for the mod to function, but you can optionally erase the Text from the Content of txtOutput2 and txtOutput3 on the HUD. Since our mod won't update this text, if you skip this step you'll see "Text Block 2" and "Text Block 3" on the HUD.
    Updated HUD blueprint

And that's it! Make sure all your blueprints have been compiled, then build and launch your mod! As you run around the space rig, you'll see coordinates for the player being updated. You might notice that the game uses centimeters for units.

HUD in Spacerig
Part 4: Showing the HUD in caves

At this point, you have your fancy HUD in the spacerig, but you won't be able to see it in caves.

For one thing, we never made an InitCave actor blueprint. Let's make one now and spawn the BP_AdventurousMod from it.

InitCave blueprint

This was a necessary step, but it's still not sufficient to show the HUD in caves. Let's fix that.

This next part I can't take credit for. I actually couldn't figure out why the HUD wasn't working in caves until I checked on Discord and saw this post from GoldBl4d3.

The DRG Modding discord is where you'll find all of the state-of-the-art info on DRG Modding.

As GoldBl4d3 has explained, "Trying to add widgets during the mission loading screen will result in failure." This method keeps trying to add the HUD until becomes visible. It adds a short delay between each iteration to prevent looping forever.

HUD creation for caves

I recreated GoldBl4d3's solution from memory. It's actually a little different from what GoldBl4d3 posted, but it seems to accomplish the same thing. That's the great thing about coding: there's usually lots of different ways to solve a problem.


Launch a mission and try it out.

HUD in a cave
That's it for this journey! Now we can run around the level and get a general idea of where things are, and we can make our HUD show up in caves. In our next excursion, we'll use this knowledge to spawn an actor in the spacerig.