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:00,770
In the last video.
2
00:00:00,770 --> 00:00:03,920
We designed the health UI, but it still isn't functional, right?
3
00:00:03,920 --> 00:00:06,050
If we get hit, it still doesn't deplete.
4
00:00:06,050 --> 00:00:07,550
So that's what we're going to do now.
5
00:00:11,380 --> 00:00:15,910
And to do this, we want to go to the widget blueprint for the health component and go inside of the
6
00:00:15,910 --> 00:00:16,630
graph.
7
00:00:17,310 --> 00:00:18,240
And in here.
8
00:00:18,240 --> 00:00:20,940
We just want to try this out on construction first.
9
00:00:20,940 --> 00:00:23,070
Just try to deplete all of the health first.
10
00:00:23,070 --> 00:00:27,960
And once you have that working, we're going to hook it into the actual blueprints that tell us when
11
00:00:27,960 --> 00:00:29,040
the player got hit.
12
00:00:29,040 --> 00:00:34,020
The problem right now is, though, that we cannot access anything from the designer in our graph.
13
00:00:34,020 --> 00:00:39,810
We actually need to mark these things as variables so that Unreal Engine knows that we want to change
14
00:00:39,810 --> 00:00:40,890
them in the graph.
15
00:00:41,220 --> 00:00:46,500
The thing we need now is the horizontal box, and we can actually just change the name to make it more
16
00:00:46,500 --> 00:00:46,860
obvious.
17
00:00:46,860 --> 00:00:49,110
And this is going to be the health box.
18
00:00:49,110 --> 00:00:51,690
And here you can see the is variable.
19
00:00:51,690 --> 00:00:55,110
And we just have to check this and compile and save.
20
00:00:55,110 --> 00:01:00,870
And now if we go to the graph you can see here on the left side under variables we have access to the
21
00:01:00,870 --> 00:01:01,500
health box.
22
00:01:01,500 --> 00:01:03,300
And we can just drag it out here.
23
00:01:03,810 --> 00:01:08,430
And first we just want to grab all of the images inside of the health box and change them from the green
24
00:01:08,430 --> 00:01:10,800
image to the shadow image.
25
00:01:12,710 --> 00:01:15,560
And let's just use the event construct for testing this.
26
00:01:15,560 --> 00:01:19,370
So if this widget is being instantiated, this is going to fire off.
27
00:01:19,370 --> 00:01:21,110
And we can just use this for testing.
28
00:01:21,110 --> 00:01:27,800
So here we can just get all children from the panel and we can just loop over them.
29
00:01:27,800 --> 00:01:32,990
So just for each and have a for each loop and connect the event construct to this.
30
00:01:34,390 --> 00:01:37,930
And for now we can just print string so we know what is happening here.
31
00:01:37,930 --> 00:01:41,170
Just print string and print the array element.
32
00:01:41,620 --> 00:01:45,610
And if we start the game now, you can see that we are just printing all of the images.
33
00:01:47,240 --> 00:01:52,640
And this shows us that we can get access to all of these, and we can then also make changes to the
34
00:01:52,640 --> 00:01:58,760
properties here on the right, but actually to be able to make changes, we, for example, cannot just
35
00:01:58,760 --> 00:02:05,600
call set brush here because we need to cast this because it doesn't really know that the children of
36
00:02:05,600 --> 00:02:07,670
the healthbox are images.
37
00:02:07,670 --> 00:02:10,340
It could just be any type of panel widget.
38
00:02:10,340 --> 00:02:14,090
So here we want to cast two image.
39
00:02:15,100 --> 00:02:16,120
Like this.
40
00:02:16,690 --> 00:02:22,510
And from the loop body connect here and now here we can just set brush from texture.
41
00:02:24,730 --> 00:02:26,920
And now we can just select the texture.
42
00:02:26,920 --> 00:02:28,840
And here I just want to look for square.
43
00:02:28,840 --> 00:02:30,460
And we have the green square.
44
00:02:30,460 --> 00:02:35,770
But now I just want to set everything to the shadow square which is what we use if the health is being
45
00:02:35,770 --> 00:02:37,870
depleted and compile save.
46
00:02:37,870 --> 00:02:38,980
And now let's have a look.
47
00:02:38,980 --> 00:02:42,310
I start the game and you can see all of the health is depleted.
48
00:02:44,530 --> 00:02:48,880
But we cast everything to image here, which is fine on constructor.
49
00:02:48,880 --> 00:02:54,190
But when we actually want to use the set brush from texture, we don't want to cast this again and again
50
00:02:54,190 --> 00:02:55,660
and again every single time.
51
00:02:55,660 --> 00:03:00,220
So we actually want to create a new array with the already casted images.
52
00:03:00,220 --> 00:03:03,550
So instead of just calling set brush from texture here we just get rid of this.
53
00:03:03,550 --> 00:03:07,390
Actually we can just hold alt click here and just drag it down for now.
54
00:03:07,390 --> 00:03:10,630
And now we just want to make an array where we save the images.
55
00:03:11,050 --> 00:03:16,450
So on the variables left here just call it health images.
56
00:03:17,400 --> 00:03:20,100
And make it an array of image type.
57
00:03:20,740 --> 00:03:26,950
So here object types image and object reference, which is the image we are casting to here.
58
00:03:27,370 --> 00:03:32,200
And we then want to and usually this details panel is on the right side for other blueprints.
59
00:03:32,200 --> 00:03:33,460
But here it's at the bottom.
60
00:03:33,460 --> 00:03:34,960
It still has the same things.
61
00:03:34,960 --> 00:03:37,570
And here we want to change this to an array.
62
00:03:37,870 --> 00:03:40,060
So variable type change this to an array.
63
00:03:40,060 --> 00:03:41,320
Compile and save.
64
00:03:41,320 --> 00:03:45,520
And we can then drag out these health images and get health images.
65
00:03:45,520 --> 00:03:47,260
And we can then just add.
66
00:03:48,480 --> 00:03:53,100
Like this and put this here and connect the as image here.
67
00:03:53,100 --> 00:03:57,420
So yeah, we just loop over all of the children of the health box.
68
00:03:57,420 --> 00:03:57,990
Right.
69
00:03:57,990 --> 00:04:01,620
All of these images, we are casting them to image.
70
00:04:01,620 --> 00:04:06,480
So that Unreal Engine knows that this is an image where we can call the set brush from texture on,
71
00:04:06,480 --> 00:04:08,400
and we just save it for now.
72
00:04:10,230 --> 00:04:12,720
And again, just to demonstrate, let's say uncompleted.
73
00:04:12,720 --> 00:04:17,910
Once everything is done here, we can just get the health images and we can just do a for each loop
74
00:04:17,910 --> 00:04:23,610
again like this and just connect here from completed to exec and set the brush.
75
00:04:24,530 --> 00:04:27,110
And this still works the same way, right?
76
00:04:27,110 --> 00:04:28,730
We still see the are depleted.
77
00:04:28,730 --> 00:04:35,150
This is working fine, but we can now just call this anywhere in our code, not just on the completed
78
00:04:35,150 --> 00:04:35,300
here.
79
00:04:35,300 --> 00:04:35,510
Right.
80
00:04:35,510 --> 00:04:36,860
I can disconnect this.
81
00:04:36,860 --> 00:04:40,580
And now we can actually use this when we take damage.
82
00:04:40,580 --> 00:04:46,970
So here we want to prepare a custom event which we can call when the player takes damage.
83
00:04:46,970 --> 00:04:52,280
So here just make a custom event and call it Update health.
84
00:04:52,910 --> 00:04:53,960
Like this.
85
00:04:55,380 --> 00:04:58,290
And we can just go here and connect this.
86
00:04:58,620 --> 00:05:02,400
And of course, in the end, we don't want to set all of these to the shadow square.
87
00:05:02,400 --> 00:05:06,630
But based on how much health we have left, we want to decide which of these should be shadows and which
88
00:05:06,630 --> 00:05:07,860
of these should be green.
89
00:05:07,860 --> 00:05:11,190
So here we also want to put an input.
90
00:05:11,190 --> 00:05:13,320
So select this and go to input.
91
00:05:13,320 --> 00:05:17,400
And just set this to call this current health.
92
00:05:19,050 --> 00:05:21,540
Current health and make this a float.
93
00:05:24,020 --> 00:05:24,710
Like this.
94
00:05:24,710 --> 00:05:25,790
Better to see.
95
00:05:27,540 --> 00:05:28,980
And for now, just compile and save.
96
00:05:28,980 --> 00:05:31,020
And we first want to call this in the player.
97
00:05:31,020 --> 00:05:34,680
And then after that we're going to see what we do with the current health, how we're going to implement
98
00:05:34,680 --> 00:05:35,310
this here.
99
00:05:36,590 --> 00:05:38,360
So we can go to the content drawer.
100
00:05:38,360 --> 00:05:43,370
We can go blueprints, characters player and BP player.
101
00:05:43,610 --> 00:05:47,690
And we want to of course, update the health on any damage.
102
00:05:48,050 --> 00:05:51,980
So whenever we take damage, we want to also update the health here.
103
00:05:51,980 --> 00:05:54,140
But there are a couple of problems right now.
104
00:05:54,140 --> 00:05:57,620
We don't know how we can get a reference to the HUD.
105
00:05:57,620 --> 00:06:04,250
We also don't know how we can get a reference to the nested WB health component, because it is actually
106
00:06:04,250 --> 00:06:06,710
being spawned in the game mode.
107
00:06:07,360 --> 00:06:09,850
So that is the first hurdle we have to overcome.
108
00:06:10,180 --> 00:06:11,620
Open up the game mode.
109
00:06:11,620 --> 00:06:14,200
So blueprints GM action.
110
00:06:14,200 --> 00:06:16,750
And here we instantiate the HUD widget.
111
00:06:16,750 --> 00:06:17,770
So this is fine.
112
00:06:17,770 --> 00:06:19,780
But we don't just want to add it to the viewport.
113
00:06:19,780 --> 00:06:21,070
We also want to save it.
114
00:06:21,070 --> 00:06:26,680
So here we can just drag off and promote the variable and just call it HUD widget.
115
00:06:27,400 --> 00:06:31,900
Like this and then, well, we can also save it in between here and here.
116
00:06:31,900 --> 00:06:35,080
We just remove this line, hold alt, put this here.
117
00:06:36,130 --> 00:06:36,910
Like this.
118
00:06:36,910 --> 00:06:39,700
And then we can also connect here to add to viewport.
119
00:06:40,270 --> 00:06:43,450
So we save it here in the HUD widget we can compile and save.
120
00:06:44,160 --> 00:06:47,790
And we can basically just tunnel this through to the player now.
121
00:06:47,790 --> 00:06:55,110
So in the BP player on begin play, I believe we already have a reference to the game mode, right.
122
00:06:55,110 --> 00:06:58,230
So we cast, we get the game mode, we cast the GM action.
123
00:06:58,230 --> 00:07:01,680
And we can then use the GM action anywhere in our blueprint.
124
00:07:02,010 --> 00:07:07,680
So when we take damage right on any damage and open up some space on the right side here.
125
00:07:08,680 --> 00:07:12,400
We can then get our GM action.
126
00:07:12,400 --> 00:07:13,360
This one.
127
00:07:14,320 --> 00:07:17,590
Get the GM action and we can get the HUD widget.
128
00:07:18,280 --> 00:07:19,510
Which is great.
129
00:07:20,330 --> 00:07:22,460
But we cannot.
130
00:07:22,580 --> 00:07:25,400
But we still cannot just call this update health.
131
00:07:25,400 --> 00:07:25,760
Right?
132
00:07:25,760 --> 00:07:31,400
So if I try to from the HUD widget, just call the update health, we actually cannot do it.
133
00:07:31,400 --> 00:07:38,270
And the reason is that it is not on the HUD widget, but it is on the nested health component.
134
00:07:38,270 --> 00:07:39,590
So how do we get this?
135
00:07:39,590 --> 00:07:41,870
Well, we have to go to the Wbhp health.
136
00:07:41,870 --> 00:07:46,250
And also set this to is variable and compile and save.
137
00:07:46,310 --> 00:07:49,310
And now in the player also compile save.
138
00:07:49,310 --> 00:07:54,860
I can get one layer deeper and just look for the Wbhp health component.
139
00:07:55,980 --> 00:07:59,640
And now on this I can call update health.
140
00:07:59,640 --> 00:08:00,180
Right.
141
00:08:00,180 --> 00:08:05,790
So we are basically daisy chaining a couple of things together to get a reference inside another thing.
142
00:08:05,790 --> 00:08:11,670
And this allows us to go from the player to the GM action to the HUD widget to the health component.
143
00:08:11,670 --> 00:08:13,860
And then we can finally call our function.
144
00:08:14,040 --> 00:08:21,270
And now let's just open up some more space here and just hold control to select the others.
145
00:08:21,870 --> 00:08:26,850
And now we just want to wedge this in here and connect this.
146
00:08:26,850 --> 00:08:30,900
And we have to give it a value for the current health.
147
00:08:31,440 --> 00:08:32,730
And how do we get this.
148
00:08:33,549 --> 00:08:41,409
And we get this from our BPC vitality and just get current health and plug this in here.
149
00:08:42,900 --> 00:08:44,760
And now we can just compile and save.
150
00:08:44,790 --> 00:08:49,740
You see, in the health component we don't call on construct.
151
00:08:49,740 --> 00:08:51,270
We don't change the brush.
152
00:08:51,270 --> 00:08:52,560
We only make this array.
153
00:08:52,560 --> 00:08:55,980
So if we just start the game we just have the green squares.
154
00:08:55,980 --> 00:08:56,550
This is fine.
155
00:08:56,550 --> 00:09:02,310
But if I get hit, you can see that the player talks to the game mode, which talks to the HUD, which
156
00:09:02,310 --> 00:09:06,000
then talks to the health component, and we deplete all of the health.
157
00:09:06,000 --> 00:09:11,520
Of course, now we want to update this to not deplete all of the health, but show the remaining health.
158
00:09:12,180 --> 00:09:15,630
And this is the reason we passed the current health through.
159
00:09:15,630 --> 00:09:21,960
So we can now use this to decide if all of these blocks should be the shadow blocks, or if these blocks
160
00:09:21,960 --> 00:09:24,180
should be the green blocks.
161
00:09:24,600 --> 00:09:27,840
And to do this we need to compare the array index.
162
00:09:27,840 --> 00:09:31,290
So this is always going to loop over the health right.
163
00:09:31,290 --> 00:09:34,650
So it is going to give us a number starting at zero.
164
00:09:34,650 --> 00:09:38,130
So this is going to be 012345.
165
00:09:38,130 --> 00:09:40,020
So let's say we have three health.
166
00:09:40,020 --> 00:09:41,820
We can just check for the index.
167
00:09:41,820 --> 00:09:43,830
And then we say well this one should be green.
168
00:09:43,830 --> 00:09:46,350
So zero one and two should be green.
169
00:09:46,350 --> 00:09:50,250
If we have three health and everything else after this should just be the shadow.
170
00:09:50,250 --> 00:09:53,550
And this is a thing if you're familiar with programming, right.
171
00:09:53,550 --> 00:09:55,380
An array always starts at zero.
172
00:09:55,380 --> 00:09:57,750
And this is something that often trips people up.
173
00:09:57,750 --> 00:10:02,370
So we have to compensate for that by adding a plus one.
174
00:10:03,060 --> 00:10:03,780
Plus one.
175
00:10:03,780 --> 00:10:07,080
And now this is actually going to show us 1234.
176
00:10:07,080 --> 00:10:09,060
So this is going to be not zero anymore.
177
00:10:09,060 --> 00:10:11,250
So this is going to start at 1234.
178
00:10:11,250 --> 00:10:15,660
And this just makes it easier for us to compare the health to the array index.
179
00:10:15,660 --> 00:10:17,670
And the health is a float.
180
00:10:17,670 --> 00:10:23,010
So we cannot actually compare a float with an integer.
181
00:10:23,010 --> 00:10:26,370
And this is why we have to floor this.
182
00:10:26,370 --> 00:10:32,010
So floor just means it's going to cut off all of the decimal spots, and it's only going to keep the
183
00:10:32,010 --> 00:10:33,390
number in the front.
184
00:10:33,390 --> 00:10:34,710
And now what do we do here.
185
00:10:34,710 --> 00:10:41,370
We check if the health the current health for this loop is bigger or equal.
186
00:10:45,390 --> 00:10:47,430
Then the current index.
187
00:10:48,000 --> 00:10:52,950
And now based on this, we can decide if we want to show the shadow texture or the green texture.
188
00:10:53,400 --> 00:10:56,730
So here we can just use a select.
189
00:10:57,500 --> 00:11:00,140
And plug this in which we just talked about.
190
00:11:00,140 --> 00:11:00,650
Right.
191
00:11:00,650 --> 00:11:04,160
So if this is true then we use the square.
192
00:11:04,760 --> 00:11:05,600
Green.
193
00:11:05,600 --> 00:11:09,020
If this is not true, use the square shadow.
194
00:11:11,250 --> 00:11:14,850
And now we can just compile and save and let's check this out.
195
00:11:15,530 --> 00:11:19,430
I go here, I get hit and you can see we deplete one health.
196
00:11:19,430 --> 00:11:20,840
The second one is gone.
197
00:11:20,840 --> 00:11:23,540
And now this is a working system.
198
00:11:25,300 --> 00:11:29,290
Right, and we can go all the way until we are defeated.
199
00:11:29,320 --> 00:11:30,580
Just take some more damage.
200
00:11:30,580 --> 00:11:31,330
And like this.
201
00:11:31,360 --> 00:11:32,080
We are defeated.
202
00:11:32,080 --> 00:11:38,140
It resets and you can see that actually, now the health doesn't reset unless we get hit again.
203
00:11:38,140 --> 00:11:41,020
So this is another problem that we have to fix.
204
00:11:41,020 --> 00:11:43,510
But in general the system is working.
205
00:11:43,960 --> 00:11:48,940
And if you're rather new to programming, this part with the loop might be a little bit intimidating,
206
00:11:48,940 --> 00:11:52,690
might be a little bit confusing, and you'll just get used to this over time.
207
00:11:52,690 --> 00:11:54,640
You don't have to fully understand it yet.
208
00:11:54,640 --> 00:11:58,900
But basically, like I said before, we're just iterating over all of these.
209
00:11:58,900 --> 00:12:05,830
And then for every step in the loop we decide, is this bigger or equal than the number of health we
210
00:12:05,830 --> 00:12:06,280
have left?
211
00:12:06,280 --> 00:12:10,960
And then we just decide based on this, and you could use some print strings to just show you the numbers,
212
00:12:10,960 --> 00:12:16,180
show you more what's going on here if you have a hard time understanding this, but arrays are prominently
213
00:12:16,180 --> 00:12:20,200
used, it's something you have to get used to and they can be so helpful.
214
00:12:20,200 --> 00:12:25,840
Now let's take care of the last issue, which like I said, if we get respawned, the health doesn't
215
00:12:25,840 --> 00:12:27,280
reset in the HUD.
216
00:12:27,280 --> 00:12:29,680
And this is a very easy thing to fix.
217
00:12:30,480 --> 00:12:31,560
On the beep player.
218
00:12:31,560 --> 00:12:36,960
We can just get this entire thing which we put under the any damage, right where we update the health
219
00:12:36,960 --> 00:12:43,680
to the current health, we can just copy this, control C and go to begin play and open up some space
220
00:12:43,680 --> 00:12:44,220
here.
221
00:12:45,750 --> 00:12:47,220
Uh, this one actually, as well.
222
00:12:47,400 --> 00:12:48,900
Pull this up as well.
223
00:12:48,900 --> 00:12:54,450
And just after the falling lateral friction, because this doesn't block anything, we can just control
224
00:12:54,450 --> 00:12:57,930
V to paste this in here and go like this.
225
00:12:59,120 --> 00:13:05,840
And this basically just tells the player and basically this just makes the player update the health
226
00:13:05,840 --> 00:13:08,570
one time after it's being spawned or respawned.
227
00:13:08,570 --> 00:13:12,260
So we can just compile and save and let's take some damage.
228
00:13:14,400 --> 00:13:15,570
Now I'm at low health.
229
00:13:15,570 --> 00:13:17,130
Let's have a look at what happens.
230
00:13:17,890 --> 00:13:18,850
I get defeated.
231
00:13:18,880 --> 00:13:22,000
We respawn and the health is being set back.
232
00:13:22,030 --> 00:13:25,000
I take damage again and the health is still correct.
233
00:13:25,000 --> 00:13:30,640
And this is the reason that we put this on the game mode so we don't have to worry about the whole thing.
234
00:13:30,640 --> 00:13:34,870
Is all the player got these spots, we have to despawn the UI, we have to respawn it again.
235
00:13:34,870 --> 00:13:40,480
And we kind of sidestepped that whole issue and also made it more optimized this way.
236
00:13:40,480 --> 00:13:46,030
And these are the basics for how to use UI, how to make it functional, and the concepts you've learned
237
00:13:46,030 --> 00:13:46,180
here.
238
00:13:46,180 --> 00:13:51,670
You can apply that to stamina systems, mana systems, and a lot of other things you can do with just
239
00:13:51,670 --> 00:13:53,800
this basic knowledge and understanding.
240
00:13:53,800 --> 00:13:55,750
So I hope you can come up with something cool.
241
00:13:55,750 --> 00:14:00,880
And maybe if you want, you could add a bullet count or make a small challenge for yourself with the
242
00:14:00,880 --> 00:14:01,900
shot energy.
243
00:14:01,900 --> 00:14:04,150
But yeah, this wraps up the UI.
244
00:14:04,150 --> 00:14:06,730
And next we're going to get into playing sounds.
22326
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.