Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,080 --> 00:00:04,280
Our goal over the next couple of videos will be making the health UI for the player.
2
00:00:04,280 --> 00:00:08,930
However, in order to do that, we first need to build up a basic understanding about how widgets and
3
00:00:08,930 --> 00:00:10,490
UI work in Unreal Engine.
4
00:00:10,550 --> 00:00:14,030
In my other course, some people ask me to show how to make a main menu.
5
00:00:14,060 --> 00:00:18,230
However, I believe that is too big of a side tangent and would take many hours to cover correctly.
6
00:00:18,230 --> 00:00:23,270
And that is not the point of this course, and also not of the other course, but the basic UI knowledge
7
00:00:23,270 --> 00:00:26,630
you're going to gain over the next couple of lessons is going to put you in the right direction, and
8
00:00:26,630 --> 00:00:29,840
you can then figure out the rest for yourself if you want to make a main menu.
9
00:00:30,020 --> 00:00:34,220
Before making the health system, let's just start out by showing some text on the screen.
10
00:00:34,550 --> 00:00:41,840
Go to the content drawer, go to content and here right click make a new folder and just called widgets.
11
00:00:41,840 --> 00:00:46,010
And widgets is just the name that Unreal Engine uses for their UI elements.
12
00:00:46,040 --> 00:00:50,480
First we want to create our overarching HUD widget, which is going to cover the entire screen, and
13
00:00:50,480 --> 00:00:54,500
we can then put child widgets inside of it to build out the other small elements.
14
00:00:55,010 --> 00:00:58,970
Just right click here and then go to User Interface.
15
00:00:58,970 --> 00:01:01,370
And here we have the Widget Blueprint.
16
00:01:01,370 --> 00:01:02,780
So just click on this.
17
00:01:02,780 --> 00:01:05,600
And here we can also base this off a certain class.
18
00:01:05,600 --> 00:01:09,230
But we just want to use the basic user widget under common.
19
00:01:09,230 --> 00:01:10,220
Just click on this.
20
00:01:10,220 --> 00:01:14,120
And here we usually call these WB for Widget Blueprint.
21
00:01:14,120 --> 00:01:15,860
And this one is going to be HUD.
22
00:01:16,500 --> 00:01:17,760
Wbhp had.
23
00:01:18,490 --> 00:01:20,080
And then open it up.
24
00:01:20,470 --> 00:01:22,210
And this is something completely new.
25
00:01:22,240 --> 00:01:25,270
You haven't seen before, but we're gonna go through it step by step.
26
00:01:25,900 --> 00:01:31,030
A widget blueprint basically consists of two different parts, and here on the right side we can switch
27
00:01:31,030 --> 00:01:36,130
between the designer, which you see right now, which lets us create how the interface looks, and
28
00:01:36,130 --> 00:01:39,670
the graph, which is very similar to the blueprints we've been using so far.
29
00:01:39,670 --> 00:01:41,860
And this is where we can implement logic.
30
00:01:42,220 --> 00:01:44,560
The events here have a little bit of a different name.
31
00:01:44,560 --> 00:01:48,790
So the event pre-construct is similar to the construct event in the blueprint.
32
00:01:48,790 --> 00:01:54,790
The construct event construct is similar to the begin play in the blueprint and tick is just tick the
33
00:01:54,790 --> 00:01:55,600
same thing.
34
00:01:56,250 --> 00:01:58,320
And here on the left side we also have the functions.
35
00:01:58,320 --> 00:01:59,520
We have macros, variables.
36
00:01:59,520 --> 00:02:03,930
We can kind of do similar things as we did in the player blueprint in all of our other blueprints,
37
00:02:03,930 --> 00:02:09,150
but one difference is that the details panel is here on the bottom left instead of on the right side.
38
00:02:09,150 --> 00:02:10,650
So this is a little bit confusing.
39
00:02:10,650 --> 00:02:14,610
So if you want to set up the default values and things, we have to do it here on the left side.
40
00:02:14,610 --> 00:02:16,200
But it's still the same thing.
41
00:02:16,200 --> 00:02:19,830
We're going to make use of all of this later to pass through how much health the character has, and
42
00:02:19,830 --> 00:02:22,140
then display the health on the UI.
43
00:02:22,140 --> 00:02:26,100
But for now, let's just have a look at the designer and check out how this works.
44
00:02:26,100 --> 00:02:28,710
And this screen is kind of a science in itself.
45
00:02:28,710 --> 00:02:32,610
If you want to really master all of the different elements here and have a deep understanding, it's
46
00:02:32,610 --> 00:02:36,990
going to take you weeks, if not months, and we're only going to cover the basics that we need for
47
00:02:36,990 --> 00:02:39,270
our game and for the overarching HUD.
48
00:02:39,300 --> 00:02:42,720
The first thing we want to look for is a canvas.
49
00:02:43,050 --> 00:02:48,390
And this is just if we drag it here, it's just the basic outline, and the canvas lets us place other
50
00:02:48,390 --> 00:02:49,860
things on top of it.
51
00:02:49,860 --> 00:02:52,920
So we can then put the health bar here, maybe put some text here.
52
00:02:52,920 --> 00:02:54,180
And to all of these kind of things.
53
00:02:54,180 --> 00:02:57,120
And the canvas is the parent that lets us place things in here.
54
00:02:57,120 --> 00:03:02,760
So just for example, we can go in here and maybe drag in a button and you can see we can place it anywhere
55
00:03:02,760 --> 00:03:03,540
we want.
56
00:03:03,690 --> 00:03:05,220
We can drag in an image.
57
00:03:07,020 --> 00:03:08,310
And the image now is this white.
58
00:03:08,310 --> 00:03:14,760
But we could select a brush here on the side and just give it some sort of material like this for example.
59
00:03:14,760 --> 00:03:15,420
Right.
60
00:03:15,420 --> 00:03:17,040
And we have text in here.
61
00:03:17,040 --> 00:03:21,150
So we could just drag in a text block and then write some text, change the size.
62
00:03:21,150 --> 00:03:23,820
And there's a lot of things we can do here with sliders.
63
00:03:23,820 --> 00:03:26,190
And we have progress bars like this.
64
00:03:26,190 --> 00:03:28,500
And there's just many different things you can do with this.
65
00:03:28,500 --> 00:03:31,170
And then style it to actually make it look nice.
66
00:03:31,170 --> 00:03:35,790
But for now, let's just select all of these, hold shift and just hit delete on the keyboard.
67
00:03:35,790 --> 00:03:40,950
And what we want to do is just show some text in the middle of the screen for now, and then actually
68
00:03:40,950 --> 00:03:44,430
have that display in the game, because just making it here is not enough.
69
00:03:44,430 --> 00:03:47,940
We actually have to tell the game to spawn this widget blueprint.
70
00:03:48,450 --> 00:03:54,150
So let's just get a text element, drag it in here in the canvas, and we can then select it.
71
00:03:54,150 --> 00:03:57,750
And here on the right side we have a lot of options and it's a little bit overwhelming.
72
00:03:57,750 --> 00:03:59,250
There's so many options available.
73
00:03:59,250 --> 00:04:01,620
But for now we just want to change the text.
74
00:04:01,620 --> 00:04:05,130
So under content text just write in hello world.
75
00:04:05,930 --> 00:04:06,920
And hit enter.
76
00:04:06,920 --> 00:04:13,190
And you can see if we zoom in here, by the way, right click and drag and the mouse wheel to zoom.
77
00:04:13,190 --> 00:04:15,320
And yeah, we can see that it says Hello world.
78
00:04:15,320 --> 00:04:16,670
But now let's make.
79
00:04:16,820 --> 00:04:21,140
But let's also make the text a little bit bigger because this is very hard to see.
80
00:04:21,140 --> 00:04:26,660
So here again on the right side we should have a font menu here font.
81
00:04:26,840 --> 00:04:29,810
And here we have the font family, the typeface the size.
82
00:04:29,810 --> 00:04:35,990
Let's just blow up the size and maybe go like 150 and we can go even bigger.
83
00:04:35,990 --> 00:04:38,210
So 250 for now.
84
00:04:38,210 --> 00:04:39,800
And this is really big now.
85
00:04:40,450 --> 00:04:42,610
Let's also change the color right.
86
00:04:42,610 --> 00:04:46,750
So for this we can just close this down go to Color and Opacity.
87
00:04:46,750 --> 00:04:48,610
And we can click this one here.
88
00:04:48,610 --> 00:04:51,010
And we can just pick the red color.
89
00:04:51,010 --> 00:04:52,360
Pick any color you like.
90
00:04:52,360 --> 00:04:54,310
And I'm just going to go with red.
91
00:04:55,360 --> 00:04:56,410
And click on okay.
92
00:04:56,410 --> 00:04:58,630
And this is how we can make changes to the text.
93
00:04:58,660 --> 00:05:01,540
One other thing you'll also use often is under font.
94
00:05:02,070 --> 00:05:07,590
We have a outline setting so we can set the outline size to let's say maybe two.
95
00:05:07,860 --> 00:05:14,310
And then you can see we get this black rim around the text which will make it easier visible.
96
00:05:14,760 --> 00:05:17,910
But the biggest problem right now is that our text is anchored.
97
00:05:17,910 --> 00:05:19,440
And you can see this thing here.
98
00:05:19,440 --> 00:05:21,870
This is the anchor to the top left.
99
00:05:21,870 --> 00:05:27,120
And this means no matter what size our screen is, the text will always be hooked into the top left
100
00:05:27,120 --> 00:05:27,540
side.
101
00:05:27,540 --> 00:05:29,970
However, we want to show this text in the middle.
102
00:05:30,330 --> 00:05:35,460
And to do this again we need to just select the text and all the way at the top you can see the anchors,
103
00:05:35,460 --> 00:05:40,470
and here you can see we anchor it to the top left, which it is right now we can anchor it to the middle.
104
00:05:40,470 --> 00:05:43,920
We can also kind of stretch it or go across the entire screen.
105
00:05:43,920 --> 00:05:46,230
So there's a lot of options here that we can use.
106
00:05:46,230 --> 00:05:48,510
And this kind of depends on what you want to do.
107
00:05:48,510 --> 00:05:52,860
But now if we just click on center this alone doesn't really do much.
108
00:05:52,860 --> 00:05:56,910
It is now centered here, but it still isn't aligned with this.
109
00:05:56,910 --> 00:05:58,170
So we actually want to.
110
00:05:58,170 --> 00:05:59,400
And you can also read this here.
111
00:05:59,430 --> 00:06:01,500
Hold shift to update the alignment.
112
00:06:01,500 --> 00:06:03,840
And then hold control to update the position.
113
00:06:03,840 --> 00:06:06,900
So we want to hold shift and control and then click here.
114
00:06:06,900 --> 00:06:10,830
And this is already a lot better but it still isn't perfect.
115
00:06:10,830 --> 00:06:15,750
And the reason this isn't perfect is because it actually only understands this box.
116
00:06:15,750 --> 00:06:17,760
It doesn't really know how big the text is.
117
00:06:17,760 --> 00:06:23,340
So we can drag this box and make sure that it kind of matches the text size roughly.
118
00:06:23,980 --> 00:06:24,940
Like this.
119
00:06:24,940 --> 00:06:29,290
And then we just do the anchoring again, hold shift and control.
120
00:06:29,440 --> 00:06:31,390
And now we are in the middle.
121
00:06:31,390 --> 00:06:35,710
One more thing we could also do is let's say we have this one a little bit bigger.
122
00:06:35,710 --> 00:06:39,010
We can also use the center option.
123
00:06:39,010 --> 00:06:41,890
So here for justification we can also use this one.
124
00:06:41,890 --> 00:06:42,490
Right.
125
00:06:42,490 --> 00:06:45,760
And now we justified inside of this box.
126
00:06:45,760 --> 00:06:48,610
And now we can again just anchor it to the middle.
127
00:06:48,610 --> 00:06:50,560
And we don't have to be as precise.
128
00:06:50,560 --> 00:06:54,340
As far as I know there is no way for justification for top to bottom.
129
00:06:54,340 --> 00:06:56,470
And it only works from left to right.
130
00:06:56,470 --> 00:07:00,460
So for top and bottom, we need to make sure that the box size matches.
131
00:07:00,700 --> 00:07:04,960
Now that we have prepared our heart and the text, we actually want to show it in the game.
132
00:07:04,960 --> 00:07:07,990
Because now if I just start the game, nothing happens.
133
00:07:07,990 --> 00:07:10,090
We actually need to tell it to spawn this HUD.
134
00:07:10,570 --> 00:07:14,380
And now we have to think about where is the best place to spawn this.
135
00:07:14,380 --> 00:07:19,930
And you might think the player is a good option and this is not too bad, but we have to handle the
136
00:07:19,930 --> 00:07:21,730
issue of respawning the player.
137
00:07:21,730 --> 00:07:26,920
So we would have to despawn the HUD widget and spawn a new widget when the player is being respawned.
138
00:07:26,920 --> 00:07:32,650
But actually there is a thing about widgets and they are going to stay in memory until you load a different
139
00:07:32,650 --> 00:07:33,070
stage.
140
00:07:33,070 --> 00:07:37,510
So even if we destroy a widget to create a new one, it's still going to stay in memory.
141
00:07:37,510 --> 00:07:41,320
And I'm not sure if this is a bug or if this is just how Unreal Engine works.
142
00:07:41,320 --> 00:07:46,900
However, this has been a problem for a long time, so the best practice is actually to try to prevent
143
00:07:46,900 --> 00:07:52,360
to despawn these kind of widgets and just make them invisible and then make them visible again if you
144
00:07:52,360 --> 00:07:55,300
need them again and kind of reuse them.
145
00:07:55,300 --> 00:08:01,780
So I believe in this case, the best place to spawn this widget is actually in the game mode.
146
00:08:02,320 --> 00:08:08,320
So let's open up the game action content blueprints GM action.
147
00:08:08,320 --> 00:08:11,080
And here we want to go to Beginplay.
148
00:08:11,080 --> 00:08:14,020
And after we set up the player start this is fine.
149
00:08:14,020 --> 00:08:16,990
We then want to create widget.
150
00:08:18,360 --> 00:08:23,670
And here we just pick the WB hat which we just created in the designer.
151
00:08:24,910 --> 00:08:26,740
And this alone is also not enough.
152
00:08:26,740 --> 00:08:29,080
If I start the game now, still nothing happens.
153
00:08:29,080 --> 00:08:32,409
It is being technically created, but it's not showing.
154
00:08:32,409 --> 00:08:37,390
And for this we have to look for, uh, add to viewport.
155
00:08:38,419 --> 00:08:42,260
And now if we start the game, you can see that it is showing up.
156
00:08:42,260 --> 00:08:43,580
So this is working.
157
00:08:46,240 --> 00:08:48,640
And this is basically how you create a widget, right?
158
00:08:48,640 --> 00:08:50,140
So you create the widget blueprint.
159
00:08:50,140 --> 00:08:55,090
You set something in the designer, and then you think about where is the best place to spawn this.
160
00:08:55,090 --> 00:08:57,760
In many cases, it is going to be the game mode.
161
00:08:57,760 --> 00:08:59,950
In some cases it's going to be the player.
162
00:08:59,950 --> 00:09:01,960
And this is how this works.
163
00:09:01,960 --> 00:09:06,730
And for the owning player we can just get player controller.
164
00:09:07,810 --> 00:09:10,060
And this is just a best practice.
165
00:09:10,060 --> 00:09:13,600
So we can then use the player controller inside of the widget.
166
00:09:13,600 --> 00:09:17,560
The widget knows who it belongs to and we only have one player, so this is fine.
167
00:09:17,560 --> 00:09:21,430
But actually we are going to set a different player reference as well later on.
168
00:09:22,180 --> 00:09:27,040
And just to show you one more cool thing, because we anchored this in the middle, even if we just
169
00:09:27,040 --> 00:09:31,900
start the game now and I resize the window, it is always nicely in the middle.
170
00:09:31,900 --> 00:09:34,750
And this is the strength of using anchors.
171
00:09:35,110 --> 00:09:37,660
And this covers the very basics of UI.
172
00:09:37,660 --> 00:09:40,240
In the next video we're going to design our health UI.
16755
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.