522 Game Development and Simulation with Unreal Technology
8.4 CREATING THE HUD
In the previous section, we set up a system to spawn balls on a timer and destroy
them as the play er approaches. For th is section , we will be expandin g up on that
functionality. The first perso n template provides us with a HUD blueprint or Heads
Up Display that, a t this time, only contains a crosshair in the middle of the screen.
We will be creating a custom HUD to display the remaining time, high-score, and
current score. Almost all video games these days have some sort of persistent HUD
to display score, time, kills, enemies, maps, items, and many other things. Using
blueprints to create a HUD is a fairly simple pro cess while still being quite powerful.
Just like in the case with other blueprint classes, H U D s can be made entirely using
blueprints.
FIND ON THE WEBSITE
To find updates to this tutorial and upda te d instructions about its implementa-
tion on othe r UE4 versions, p le ase visit the book’s companion Website at:
http://www.RVRLAB.com/UE4Book/
TUTORIAL 8.5 Creating the MyHUD Blueprint
The first person template gives us a HUD by default; however, if we needed to
create one from scratch it would be beneficial to learn how.
CREATING TH E HUD
First we will h ave to create the HUD blueprint. To do this:
1. Navigate to the Blueprints folder in the Con tent Browser.
2. Create a new blueprint.
3. When you pick a parent class, you will need to sear ch for HUD at the bottom a s
the HUD class contains specific functions just for drawing the HUD on the screen.
4. Once you have found the parent class, name your blueprint MyNewHUD and save
the project.
5. Open the new b lueprint and go to the blank event graph.
6. The main event that we will be using is called Event Receive Draw HUD,
which will constantly u pdate th e HUD and draw the infor mation we want.
7. In th is case, we are just going to p la ce th e crosshair back on the scree n.
8. Using th e exec (white) pin, attach a function called Draw Texture. As you can
see from this function, we are given quite a lot of options.
9. To position the crosshair in the center of the screen, we need to get the halfway
point for the width and height of the scr een. We ca n do this by taking the Size X
and Size Y pin s and dividing them in half with a math function.
10. Drag a wire from Size X and place a div ide function.