Welcome back.
Now we have our health and Mana Globes showing on the screen, but we're adding those from the level
blueprint.
If we open our level blueprint, we see that we're creating a widget and adding it to the viewport here.
That's not what we want to do.
That was just for testing purposes.
I'm going to go ahead and remove that and close our level blueprint.
We don't want that to be something that depends on code in our level blueprint.
Instead, I'd like to have a designated place for creating our overlay widget, adding it to the viewport
and later actually assigning its widget controller.
Now our game mode has a number of default classes.
If we go to game and or a game mode, here are the default classes and we can set a HUD class.
And a HUD class is really good for doing HUD related things such as drawing widgets to the screen.
And that's where I'd like to add the overlay widget.
So I'm going to create a HUD class and we'll make a ora HUD cplusplus class to base our HUD blueprint
on.
I'll go ahead and close out of all these tabs and we'll go to cplusplus classes ora public.
And this can go into UI and I'll go ahead and right click new Cplusplus class and we'll choose the base
class to be HUD choosing next.
And in the UI folder, I'd like a HUD folder where I can store my Ora HUD class.
So I'm going to call this ora HUD and create class and I'll go ahead and close the editor, save all.
And we should see a HUD folder here in UI.
Now, a nice little shortcut in Ryder is if you have multiple folders open like this, you can collapse
private, you can collapse public.
And when you open them again, all those folders are closed.
So it looks nice and neat.
So in UI we have HUD and HUD.
We have Ora HUD and ora hud Dhcp.
Excellent.
So what do we want to do in Ora?
HUD Well, we want to draw our overlay to the screen, that overlay widget.
So I'm going to want to have a variable to store the overlay widget and a variable to store the overlay
widget class that I'd like to spawn.
So I'm going to go ahead and make a public section and make a variable for the widget itself so we can
store it once we've created it.
This will be a T object pointer of type u ora user widget.
Now it's asking if I want to include I'm just going to add the forward declaration for it and I'm going
to call this overlay widget.
This will be the widget once we create one.
This will get a uproperty macro, but I also need to know the class.
So to create the widget, I need to know the class of widget to create.
So this one I'll make a private variable.
It's going to be a subclass of.
So I'm going to make a T subclass of based on you or a user widget and I'll call this overlay widget
class and this one gets a new property with edit anywhere so I can set it from our HUD blueprint.
Now we just need a way to add this to the viewport.
Now if we want we can just add it to the viewport and begin play for now just to get things working
and see how it works.
We can do that.
But later, when we're setting our overlay widgets, widget controller timing is going to be important
and we'll cross that bridge when we get there.
For now, I just want to see the overlay on the screen drawn by Ora HUD, so I'm going to override Beginplay.
That's a protected function.
So we'll make protected section and we'll say virtual void begin play.
That's an override.
We're going to go ahead and generate the definition and we can create and add that widget to the viewport.
So first we need to call create widget.
We need to say create widget.
That's a template and we have to use U user widget for that.
Now the first input is the owning object, and here in the HUD we can actually pass in the world for
that.
The world can own this object and for the user widget that's going to be our overlay widget class.
And this function returns a user widget pointer.
So we're going to create a local one called Widget.
So we've got our widget and we can simply add it to the viewport by calling add to viewport.
And it looks like writer included something I didn't need.
There something you need to be aware of with writers auto includes.
So now all that's left is to make a blueprint based on our HUD.
Assign that in our game mode blueprint.
Make sure that the HUD has our overlay widget class and then play test.
And that's going to be your quest.
So I'd like you to create the aura HUD blueprint.
Call it BP Aura HUD, and you're going to set that overlay widget class, that subclass of make sure
to set that in the blueprint and then you can assign this in the game mode.
So go to BP aura game mode and assign BP aura HUD for the default HUD class.
So pause the video and do this now.
Okay.
So we can compile and launch.
And here in the editor we can go to blueprints and under UI, I'd like a new folder called HUD and we'll
put our HUD in that HUD folder.
We'll right click, make a new blueprint class and search for Aura HUD.
Choosing that I'm going to select it and call this BP or HUD.
And in Aura HUD, we can choose our overlay widget class.
And here it is under Aura HUD Overlay Widget class.
We can choose WPP overlay and compile and save.
And then we can go into our game folder, go to our aura game mode and change HUD class to BP Aura HUD
compile and save.
And now in Begin play, the HUD should construct and add the widget to the viewport pressing play.
We see that it does, and everything works just fine.
So I'm going to save all.
This is looking great.
We're now ready to start assigning widget controllers to our widgets so that that way we can start controlling
values in those widgets, such as the percent for our progress bars or in our case, progress globes.
So excellent job.
And it looks like Aura has frozen here.
It looks like she's played the first idle animation, but it's not looping is it?
Looks like it just stopped.
So just a really quick fix.
I'm going to go to Blueprints.
We'll go to Character, Aura, AVP, Aura and Open idle.
Select the idle here and let's check loop animation compile, and let's make sure that she doesn't just
freeze.
After that first idle animation and now it's looping and we're looking great.
Excellent.
All right.
I'll see you in the next video.