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.
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:
AdventurousMod
here but substitute "AdventurousMod" with whatever you want throughout these adventures.AdventurousMod
folder, create an actor blueprint called BP_AdventurousMod
.WBP_AdventurousModHUD
.
txtOutput1
, txtOutput2
, and txtOutput3
.
BP_AdventurousMod
and edit the blueprint so it displays the HUD when the game begins. Save a reference to the widget as HUD Ref
.
Content
folder and create the InitSpacerig
actor blueprint.
InitSpacerig
blueprint and make it spawn an instance of your mod.
This should have been a review for you, so hopefully it was easy for you to follow along.
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?
BP_AdventurousMod
blueprint and add some nodes to set the text of each text block:
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.
You may have noticed the code in the Print "Hello Whale Piper"
macro seems very repetive. We'll address that in a later journey.
If you've made it this far, you're probably eager to actually have something interesting happen! Let's do that now:
AdventurousMod
folder and create a blueprint for a new actor called BP_PlayerPosition
. Open this blueprint.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.
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
.
get
for your Player Character Ref
near the Event Tick
node and drag off a node called GetActorLocation
.
BP_AdventurousMod
actor. From here, drag out the following chain of nodes:
HUD Ref
→ Get Txt Output 1
→ SetText
.
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!
Event Tick
to that of SetText
. The whole blueprint should now look like this:
BP_AdventurousMod
blueprint.Print "Hello Whale Piper"
node.Create HUD
macro and add a Spawn Actor from Class
node. Set the class to BP_PlayerPosition.
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.
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.
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.
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.
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.
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.