﻿1
00:00:04,120 --> 00:00:04,630
‫Okay.

2
00:00:04,630 --> 00:00:08,980
‫So our goal for this video is to implement death for our Pons.

3
00:00:08,980 --> 00:00:17,020
‫So if I get hit a couple of times from our tower, you'll see that I have disappeared because my tank

4
00:00:17,020 --> 00:00:17,770
‫has died.

5
00:00:17,770 --> 00:00:23,650
‫And if I'm skilled enough, if I can go ahead and destroy one of them, you'll see that it disappears

6
00:00:23,650 --> 00:00:24,220
‫as well.

7
00:00:24,220 --> 00:00:29,200
‫So we're going to implement death for these pawns in this video.

8
00:00:29,290 --> 00:00:31,240
‫Hello and welcome back.

9
00:00:31,270 --> 00:00:36,790
‫Now we're already applying damage to the pawns when they're being hit by projectiles.

10
00:00:36,790 --> 00:00:40,600
‫We now need to figure out how we're going to handle after death.

11
00:00:40,600 --> 00:00:45,910
‫This means we're going to need some sort of function to handle the destruction of a particular actor.

12
00:00:45,910 --> 00:00:49,030
‫So we're going to create a handle destruction function.

13
00:00:49,030 --> 00:00:55,510
‫We also need an actor die to function, which can allow the game mode to handle what happens when an

14
00:00:55,510 --> 00:01:01,480
‫actor in our world dies and we're going to call this actor died function when the health value reaches

15
00:01:01,480 --> 00:01:03,340
‫zero for a particular pawn.

16
00:01:03,340 --> 00:01:07,630
‫So let's talk about a bit of a roadmap for how we're going to implement this system.

17
00:01:07,630 --> 00:01:14,080
‫We know that we have a projectile and it's calling apply damage and this results in the damage taking

18
00:01:14,080 --> 00:01:18,610
‫function responding to that delegate broadcast in the health component.

19
00:01:18,610 --> 00:01:21,100
‫So we need to figure out what to do from there.

20
00:01:21,100 --> 00:01:26,230
‫Well, our game mode can have a function to handle when an actor dies.

21
00:01:26,230 --> 00:01:30,370
‫So in damage taken, we can check to see if the health reaches zero.

22
00:01:30,370 --> 00:01:37,210
‫And at that point we can call the actor died function on the game mode and from there our pawn can handle

23
00:01:37,210 --> 00:01:38,440
‫its destruction.

24
00:01:38,440 --> 00:01:44,500
‫So ultimately it'll be up to the game mode to call the handle destruction function on the actor that

25
00:01:44,500 --> 00:01:45,010
‫died.

26
00:01:45,010 --> 00:01:49,660
‫So we have a bit of a game plan, so let's outline the steps to take to implement this.

27
00:01:49,660 --> 00:01:54,400
‫First, we're going to create the handle destruction function and we're going to place this on the base

28
00:01:54,400 --> 00:01:58,900
‫pawn class to handle functionality that should happen when any of our pawns die.

29
00:01:58,900 --> 00:02:04,090
‫And we'll also implement this in the tank and the tower classes, since they'll each have their own

30
00:02:04,090 --> 00:02:09,520
‫unique functionality when they die, then we'll create an actor died function and place this on the

31
00:02:09,520 --> 00:02:13,090
‫game mode class so that we can call handle destruction from there.

32
00:02:13,090 --> 00:02:18,730
‫After that we'll call handle destruction in the actor died function on the game mode and then we can

33
00:02:18,730 --> 00:02:23,320
‫call actor died from the health component when the health reaches zero.

34
00:02:23,320 --> 00:02:27,640
‫So let's start with our first step creating the handle destruction function.

35
00:02:27,640 --> 00:02:33,430
‫So I'm here in Base Pond H and I'd like to add this handle destruction function.

36
00:02:33,430 --> 00:02:38,740
‫Now I'm planning on calling this from the game mode, which means it's going to need to be a public

37
00:02:38,740 --> 00:02:42,850
‫function so I can place this function here in the public section.

38
00:02:42,940 --> 00:02:46,840
‫It's going to be void and I'm going to call it handle destruction.

39
00:02:47,890 --> 00:02:50,710
‫Now, it doesn't need to take any input parameters.

40
00:02:50,860 --> 00:02:55,360
‫It's simply going to handle the destruction of this particular pawn.

41
00:02:55,360 --> 00:03:01,840
‫So let's implement this function in the base pawn CP file and I'm going to place it right here under

42
00:03:01,840 --> 00:03:02,770
‫the constructor.

43
00:03:02,770 --> 00:03:09,550
‫So I have handle destruction and I'm going to place the a base pawn class name just before the function

44
00:03:09,550 --> 00:03:10,180
‫name here.

45
00:03:10,180 --> 00:03:15,640
‫Now this is going to be things that happen when any of the pawns based on base pawn dies.

46
00:03:15,640 --> 00:03:21,040
‫So I'm going to place a to do here that says what we're going to do in the handle destruction function.

47
00:03:21,040 --> 00:03:26,800
‫I'd like to handle all the visual and sound effects here that have to do with the pawn dying.

48
00:03:26,800 --> 00:03:32,860
‫So I'm just going to say visual slash sound effects and we'll leave it at that and we'll make sure to

49
00:03:32,860 --> 00:03:38,320
‫remember to implement this when we get to the special effects and sounds part of this section of the

50
00:03:38,320 --> 00:03:38,920
‫course.

51
00:03:38,920 --> 00:03:44,890
‫Now we have handle destruction here, but I'd like to also put a handle destruction function in both

52
00:03:44,890 --> 00:03:50,050
‫the tank and tower classes to handle what happens when those pawns die.

53
00:03:50,050 --> 00:03:54,670
‫And the most simple implementation of destruction is perhaps going to be for our tower.

54
00:03:54,670 --> 00:04:00,760
‫So let's go into Tower H and we'll add a public function here called handle destruction.

55
00:04:00,760 --> 00:04:09,130
‫So I'm going to say void handle destruction and I'm going to implement this and tower CP just under

56
00:04:09,130 --> 00:04:10,060
‫the tick function.

57
00:04:10,060 --> 00:04:17,440
‫So here's tick here's handle destruction and I'm going to prefix the function name with a tower just

58
00:04:17,440 --> 00:04:18,130
‫like that.

59
00:04:18,130 --> 00:04:24,280
‫Now in the handle destruction function for the tower, I'd like to call the super version so that handle

60
00:04:24,280 --> 00:04:29,800
‫destruction in base pawn gets called and we'll get those visual and sound effects when a tower dies.

61
00:04:29,800 --> 00:04:35,650
‫So I'm going to say super handle destruction just to make sure that that gets called.

62
00:04:35,650 --> 00:04:39,040
‫And after that, I'm simply going to destroy the tower.

63
00:04:39,040 --> 00:04:40,390
‫Now we've seen how this works.

64
00:04:40,390 --> 00:04:45,820
‫We simply call the destroy function, and that's going to handle destruction for the tower.

65
00:04:45,820 --> 00:04:52,960
‫So I can save this and close out of the tower and CP files and now I can place a handle destruction

66
00:04:52,960 --> 00:04:54,910
‫function in the tank class.

67
00:04:54,910 --> 00:05:01,570
‫So I'm going to go to tank and declare a public function here under the tick function called handle

68
00:05:01,570 --> 00:05:02,620
‫destruction.

69
00:05:03,640 --> 00:05:10,870
‫And I'm going to go to Tank CP and implement this just under tic here, not forgetting to prefix the

70
00:05:10,870 --> 00:05:13,360
‫function name with a tank.

71
00:05:13,510 --> 00:05:17,950
‫Now, just like in the tower class, we'd like to call super handle destruction.

72
00:05:19,300 --> 00:05:22,120
‫And that way we'll get those visual and sound effects.

73
00:05:22,150 --> 00:05:24,910
‫Now for the tank, we're going to do something a little different.

74
00:05:24,940 --> 00:05:27,700
‫I'd like to hide the tank rather than destroy it.

75
00:05:27,700 --> 00:05:33,550
‫And then we can disable its TIC functionality so it'll still exist in the world and we'll still be possessing

76
00:05:33,550 --> 00:05:33,730
‫it.

77
00:05:33,730 --> 00:05:35,740
‫So we still get that view from the camera.

78
00:05:35,770 --> 00:05:38,610
‫Only we won't be able to see it or move it around.

79
00:05:38,620 --> 00:05:47,710
‫So to hide the tank we can call a function called set actor hidden in game and this will take a boolean.

80
00:05:47,710 --> 00:05:51,400
‫And if we pass in true then we will effectively hide the tank.

81
00:05:51,430 --> 00:05:55,420
‫Now I'd also like to disable ticking and there's a function for that as well.

82
00:05:55,420 --> 00:05:58,810
‫It's called set actor tic enabled.

83
00:05:59,770 --> 00:06:05,260
‫And for this I'm going to pass in false, which will disable ticking for the tank.

84
00:06:05,260 --> 00:06:08,800
‫So that takes care of our handle destruction function.

85
00:06:08,800 --> 00:06:11,590
‫So we have our handle destruction function.

86
00:06:11,620 --> 00:06:16,020
‫Our next step is to create an actor died function in the game mode.

87
00:06:16,030 --> 00:06:17,440
‫So let's implement that.

88
00:06:17,440 --> 00:06:25,870
‫So I'm here in tune tanks game mode and here I can create the actor died function now I plan on calling

89
00:06:25,870 --> 00:06:32,200
‫actor died from the health component class, which means this also needs to be a public function.

90
00:06:32,440 --> 00:06:37,590
‫So I'm going to add a public section and create the actor died function.

91
00:06:37,600 --> 00:06:40,930
‫Now this will be void and I'm going to call it actor died.

92
00:06:41,170 --> 00:06:48,460
‫And this can simply take an a actor pointer called Dead Actor and now we can implement actor died in

93
00:06:48,460 --> 00:06:49,740
‫tune tanks game mode.

94
00:06:50,110 --> 00:06:58,690
‫CP So I'm going to place it here and prefix the name with a tune tanks game mode and now we have an

95
00:06:58,690 --> 00:07:00,220
‫actor died function.

96
00:07:00,220 --> 00:07:05,890
‫Now I'd like to check to see if the dead actor is the tank, which means I'm going to need a variable

97
00:07:05,890 --> 00:07:07,030
‫for the tank.

98
00:07:07,030 --> 00:07:09,460
‫So back in tune tanks game mode.

99
00:07:09,460 --> 00:07:16,540
‫I'm going to make a private section and I'm going to add a tank variable which I'm going to forward

100
00:07:16,540 --> 00:07:17,290
‫declare.

101
00:07:17,290 --> 00:07:23,290
‫And it's of type A tank pointer and I'm simply going to call this tank and I'm going to need to initialize

102
00:07:23,290 --> 00:07:27,760
‫this with the address of the tank pond, and I can do that and begin play.

103
00:07:27,760 --> 00:07:33,640
‫Now we've seen that begin play is a protected function and we're going to keep it protected here in

104
00:07:33,640 --> 00:07:36,400
‫the game mode so we can override, begin, play.

105
00:07:36,400 --> 00:07:44,110
‫So I'm going to say virtual void, begin, play, override, and I can implement it here in tune tanks,

106
00:07:44,110 --> 00:07:44,580
‫game mode.

107
00:07:44,860 --> 00:07:45,610
‫Yep.

108
00:07:45,640 --> 00:07:52,840
‫So it's going to be void begin play and I'm going to use the tune tanks, game mode class name.

109
00:07:52,990 --> 00:07:56,110
‫And the first thing I'm going to do is call super begin play.

110
00:07:57,550 --> 00:08:03,040
‫That way we get parent functionality and I can get the player pawn using gameplay statics.

111
00:08:03,040 --> 00:08:10,660
‫So I'm going to first include gameplay statics and that's in kismet slash gameplay statics as we've

112
00:08:10,660 --> 00:08:11,680
‫already seen.

113
00:08:11,800 --> 00:08:17,290
‫And here I can take Tank and assign it the value of youth gameplay statics.

114
00:08:18,230 --> 00:08:19,550
‫Guitar player palm.

115
00:08:20,360 --> 00:08:26,390
‫Now, this takes a world context object which we can use this for, and I'm going to use zero as the

116
00:08:26,390 --> 00:08:30,200
‫player index since our tank will always be player zero.

117
00:08:30,200 --> 00:08:37,430
‫Now we know that jet player -- returns an A -- pointer and tank is of type A tank, a child class.

118
00:08:37,430 --> 00:08:43,910
‫And we've seen that we need to cast to that a tank class if we'd like to store this result in an A tank

119
00:08:43,910 --> 00:08:44,510
‫pointer.

120
00:08:44,510 --> 00:08:47,450
‫So first I'm going to include the tank header.

121
00:08:47,450 --> 00:08:53,330
‫So I'm going to say include tank H and then I'm going to cast to a tank.

122
00:08:53,390 --> 00:09:00,440
‫So I'm going to say cast to a tank and I'm casting the value returned from get player --.

123
00:09:00,440 --> 00:09:02,900
‫So I'm going to place that in the parentheses here.

124
00:09:03,260 --> 00:09:08,720
‫And now we'll have a pointer to the player -- in the form of an A tank pointer.

125
00:09:08,720 --> 00:09:14,090
‫So now that we have the tank, we can check to see if our dead actor is the tank.

126
00:09:14,090 --> 00:09:21,800
‫So we can say if dead actor double equals tank now tank may be null.

127
00:09:21,800 --> 00:09:28,940
‫And that's okay because if Tank is null and dead actor refers to the tank itself, then this will fail

128
00:09:28,940 --> 00:09:34,130
‫the if check and we won't actually attempt to access a null pointer because we won't make it to the

129
00:09:34,130 --> 00:09:35,060
‫inside of this.

130
00:09:35,060 --> 00:09:41,900
‫Now, if the dead actor is in fact the tank, then I'd like to call the tank handle destruction function.

131
00:09:41,900 --> 00:09:44,870
‫So we're going to call tank handle destruction.

132
00:09:45,680 --> 00:09:52,100
‫Now, after I call the handle destruction function, I'd also like to disable input for the tank pod

133
00:09:52,100 --> 00:09:58,550
‫so I can get the tank and call the built in function that tank inherits called disable input.

134
00:09:59,540 --> 00:10:03,200
‫Now disable input requires an A player controller.

135
00:10:03,200 --> 00:10:10,430
‫Now we know that the tank class, if we come here into tank H has this player controller ref variable,

136
00:10:10,430 --> 00:10:17,270
‫which is a pointer to a player controller, which is why I'm starting to think that ref is a very awful

137
00:10:17,270 --> 00:10:19,160
‫name for this variable.

138
00:10:19,160 --> 00:10:21,320
‫Since it's not a reference, it's a pointer.

139
00:10:21,320 --> 00:10:24,260
‫I'd almost rather call it tank player controller.

140
00:10:24,350 --> 00:10:27,200
‫So in fact, why don't we go ahead and rename this?

141
00:10:27,200 --> 00:10:33,530
‫This is something that developers often do when they realize that they've given a variable, a bad name.

142
00:10:33,530 --> 00:10:36,290
‫So this code has a way to do this easily.

143
00:10:36,290 --> 00:10:42,350
‫I can highlight this variable and hit the F two key and it's asking for me to rename it.

144
00:10:42,590 --> 00:10:45,710
‫I'm going to call this tank player controller.

145
00:10:46,100 --> 00:10:47,480
‫Now check this out.

146
00:10:47,480 --> 00:10:49,790
‫It's called Tank Player Controller here.

147
00:10:49,790 --> 00:10:54,350
‫If I go to Tank CP, I'll see that it's renamed here as well.

148
00:10:54,350 --> 00:11:00,530
‫So I didn't have to go in and look for it and find every instance of player, controller, ref.

149
00:11:00,530 --> 00:11:06,050
‫I can search for tank player controller and see that it's changed everywhere that it's used here.

150
00:11:06,050 --> 00:11:08,960
‫So that's a nice refactoring skill to have.

151
00:11:08,960 --> 00:11:15,650
‫So anyway, back here in tune tanks game mode, I need to disable the input for the tank and this requires

152
00:11:15,650 --> 00:11:17,180
‫a player controller.

153
00:11:17,360 --> 00:11:23,360
‫So I'm first going to check to make sure the tank player controller is valid by saying if tank and I

154
00:11:23,360 --> 00:11:25,550
‫need to access that player controller.

155
00:11:25,550 --> 00:11:30,440
‫But recall that in tank, our player controller variable is private.

156
00:11:30,440 --> 00:11:36,860
‫Now we could expose this and make it public, or we could make a public getter function for this variable.

157
00:11:36,860 --> 00:11:40,340
‫I'd rather make a public getter as that's better programming practice.

158
00:11:40,340 --> 00:11:46,610
‫So up here in the public section, I'm going to create a public getter for tank player controller.

159
00:11:46,610 --> 00:11:53,300
‫Now it's going to return an A player controller pointer and this function is going to be called get

160
00:11:53,630 --> 00:11:55,340
‫tank player.

161
00:11:55,340 --> 00:12:02,900
‫Controller getters are typically the name of the variable with get in the front, and they're also typically

162
00:12:02,900 --> 00:12:09,830
‫made cost as this function is not designed to change anything in this class, it's only going to return

163
00:12:09,830 --> 00:12:10,970
‫the player controller.

164
00:12:10,970 --> 00:12:16,760
‫So we're going to say return tank player controller and that's all it's going to do.

165
00:12:16,760 --> 00:12:22,760
‫So now that we have a public getter function for the tank player controller, we can access the player

166
00:12:22,760 --> 00:12:25,640
‫controller here from within the game mode.

167
00:12:25,880 --> 00:12:33,080
‫So we're going to say if tank get a tank player controller and make that function call here.

168
00:12:33,080 --> 00:12:38,450
‫And if we reach the inside of this if statement, then the player controller is valid so we can move

169
00:12:38,450 --> 00:12:45,590
‫this call to tank disable input right here and we're going to pass into disabled input the tank player

170
00:12:45,590 --> 00:12:46,400
‫controller.

171
00:12:48,400 --> 00:12:51,950
‫So we'll call tank get player controller here as well.

172
00:12:51,970 --> 00:12:57,910
‫Now, while we're accessing the player controller, I'd also like to take the player controllers be

173
00:12:57,910 --> 00:13:03,640
‫show mouse cursor Boolean member variable and set this to false.

174
00:13:03,640 --> 00:13:08,830
‫So we're disabling input and we're also making sure that the mouse cursor is not shown.

175
00:13:08,830 --> 00:13:13,400
‫So that takes care of handling the functionality for when the tank dies.

176
00:13:13,420 --> 00:13:19,660
‫Now, in the case that the dead actor is not the tank, I then like to check to see if it's an instance

177
00:13:19,660 --> 00:13:21,010
‫of the tower class.

178
00:13:21,010 --> 00:13:23,200
‫So I'm going to add an else if here.

179
00:13:23,320 --> 00:13:26,410
‫So what's going to be the conditional for this elseif here?

180
00:13:26,440 --> 00:13:33,640
‫Well, I'd like to see if dead actor can be cast to an A tower, which means I'm going to need to include

181
00:13:34,360 --> 00:13:35,800
‫the tower class.

182
00:13:35,890 --> 00:13:37,300
‫So include tower.

183
00:13:38,170 --> 00:13:40,270
‫And then I'm going to attempt to cast.

184
00:13:40,270 --> 00:13:44,770
‫So I'm going to say cast, which takes angle brackets and parentheses.

185
00:13:44,770 --> 00:13:50,410
‫And what we're casting too is a tower and what we're casting is dead.

186
00:13:50,410 --> 00:13:53,410
‫Actor will attempt to cast dead actor.

187
00:13:53,410 --> 00:13:59,410
‫Now we can actually take the result of this cast and assign it and create a local variable.

188
00:13:59,410 --> 00:14:09,310
‫Here in the conditional we can say a tower pointer and we can call this destroyed tower and assign it

189
00:14:09,310 --> 00:14:11,470
‫the value returned from this cast.

190
00:14:11,470 --> 00:14:18,250
‫And if we do that, then we have access to this destroyed actor, which is our dead actor cast to a

191
00:14:18,250 --> 00:14:18,660
‫tower.

192
00:14:18,670 --> 00:14:22,630
‫Now, if this is successful, then we'll make it to the inside of the elseif.

193
00:14:22,630 --> 00:14:24,670
‫And then we can take our destroyed.

194
00:14:25,490 --> 00:14:31,430
‫Tower and we can simply call handle destruction.

195
00:14:32,870 --> 00:14:39,800
‫So now we have an actor died function here in the game mode which calls handle destruction and also

196
00:14:39,800 --> 00:14:43,910
‫handles some more death related functionality for the tank.

197
00:14:44,180 --> 00:14:45,980
‫So that takes care of step two.

198
00:14:45,980 --> 00:14:52,220
‫Creating an actor died function and while we were at it we also called handle destruction in the actor

199
00:14:52,220 --> 00:14:53,540
‫died function.

200
00:14:53,540 --> 00:14:58,150
‫So our last step is to call actor died when health reaches zero.

201
00:14:58,160 --> 00:15:04,310
‫Now in order to call this function that exists on the game mode, our health component is going to need

202
00:15:04,340 --> 00:15:07,250
‫a variable that stores the address of the game mode.

203
00:15:07,250 --> 00:15:10,340
‫So let's go into our health component class.

204
00:15:10,340 --> 00:15:16,100
‫Here's health components, and I'm going to add a private variable here just at the bottom.

205
00:15:16,100 --> 00:15:25,730
‫And this will be of type A tune tanks game mode pointer and we'll call this tune tanks game mode.

206
00:15:25,730 --> 00:15:31,010
‫Now I'm going to forward declare this so I don't have to include its header file here and then we need

207
00:15:31,010 --> 00:15:32,480
‫to access the game mode.

208
00:15:32,480 --> 00:15:38,990
‫So let's go to health component CP and if I scroll up, I see the begin play function here and that

209
00:15:38,990 --> 00:15:41,690
‫is the perfect place to get a hold of the game mode.

210
00:15:41,690 --> 00:15:44,840
‫Again, putting it in the constructor is to early.

211
00:15:44,840 --> 00:15:50,530
‫We need to make sure that the game mode has been constructed and exists before we try to access it.

212
00:15:50,540 --> 00:15:57,200
‫Now here is a handy function on game play statics called Get Game Mode and it says returns the current

213
00:15:57,200 --> 00:16:01,610
‫game mode base or null if it can't be retrieved such as on the client.

214
00:16:01,850 --> 00:16:07,730
‫Now on the client has to do with multiplayer programming and we don't have to worry about that.

215
00:16:07,730 --> 00:16:14,930
‫We are running on the one and only machine for our game, so let's scroll down and we'll see that a

216
00:16:14,930 --> 00:16:18,230
‫game mode base takes a world context object.

217
00:16:18,230 --> 00:16:24,080
‫This is just an object in the world and we've seen how to handle world context objects.

218
00:16:24,080 --> 00:16:29,030
‫So this exists in gameplay static h so let's get that include.

219
00:16:29,030 --> 00:16:35,330
‫And here in health components, CP will paste our include for gameplay statics and then we'll call get

220
00:16:35,330 --> 00:16:37,490
‫game mode here and begin play.

221
00:16:37,790 --> 00:16:40,670
‫So we're going to say tune tanks, game mode.

222
00:16:42,030 --> 00:16:44,380
‫And set that to the value of you.

223
00:16:44,400 --> 00:16:50,940
‫Gameplay statics get game mode and for the world context object.

224
00:16:50,940 --> 00:16:54,750
‫I'm going to pass in this and now we have the game mode.

225
00:16:54,750 --> 00:17:01,080
‫But of course get game mode, returns a game mode base and we're attempting to store it in the child

226
00:17:01,080 --> 00:17:06,810
‫class, a tune tanks game mode, which means we're going to need to cast.

227
00:17:06,810 --> 00:17:07,380
‫That's right.

228
00:17:07,380 --> 00:17:17,580
‫So we need to say cast to a tune tanks game mode and we're casting the result from get game mode.

229
00:17:17,580 --> 00:17:20,430
‫So I'm going to place that in the parentheses there.

230
00:17:20,430 --> 00:17:22,410
‫And we're using tune tanks game mode.

231
00:17:22,410 --> 00:17:24,840
‫So I'm going to include that header file at the top.

232
00:17:24,840 --> 00:17:26,970
‫So I'm going to say include.

233
00:17:28,960 --> 00:17:32,120
‫Tune Tanks game mode.

234
00:17:33,100 --> 00:17:36,960
‫So we have the game mode here in the health component.

235
00:17:36,970 --> 00:17:44,080
‫We're ready to go down here into damage taken and check to see if our health reaches zero.

236
00:17:44,140 --> 00:17:52,060
‫And in that case we can use our tune tanks game mode pointer to call the function actor died passing

237
00:17:52,060 --> 00:17:59,740
‫in the actor that died and this is going to be your challenge so in the health component class in damage

238
00:17:59,740 --> 00:18:06,910
‫taken you're going to check to see if the value of health has reached zero or gone below zero.

239
00:18:06,940 --> 00:18:11,260
‫If that's the case, then call actor died using the game mode.

240
00:18:11,260 --> 00:18:17,140
‫Since we have a pointer to the game mode, don't forget to check to see if this pointer is not null

241
00:18:17,140 --> 00:18:17,800
‫first.

242
00:18:17,800 --> 00:18:21,940
‫And once you call actor died, you're going to need to pass in an actor.

243
00:18:21,940 --> 00:18:25,000
‫You're going to pass in the actor that died.

244
00:18:25,000 --> 00:18:30,370
‫So pause the video and implement this in the damage taken function now.

245
00:18:33,280 --> 00:18:33,670
‫Okay.

246
00:18:33,670 --> 00:18:36,720
‫So we've already subtracted damage from health.

247
00:18:36,730 --> 00:18:41,220
‫We're now ready to check to see if that health value has reached zero.

248
00:18:41,230 --> 00:18:48,610
‫So I'm going to say if health is less than or equal to zero F and if that's the case, then it's appropriate

249
00:18:48,610 --> 00:18:49,450
‫to call.

250
00:18:49,480 --> 00:18:55,090
‫Actor died now because we need to check to see if the game mode is valid.

251
00:18:55,090 --> 00:19:02,170
‫I can place an ad here in this if check and check to see if tune tanks game mode is valid.

252
00:19:02,170 --> 00:19:07,060
‫If it's null, then it will return false here and we won't reach the inside of the if statement.

253
00:19:07,540 --> 00:19:13,600
‫So if we reach the inside of the if statement, tune tanks game mode is valid and health has reached

254
00:19:13,600 --> 00:19:14,050
‫zero.

255
00:19:14,050 --> 00:19:16,780
‫So we can say tune tanks, game mode.

256
00:19:17,980 --> 00:19:19,900
‫And we can call actor died.

257
00:19:20,830 --> 00:19:27,160
‫And this takes an actor and we know that the actor that died is going to be the damaged actor.

258
00:19:27,160 --> 00:19:29,950
‫So we're going to pass in damaged actor.

259
00:19:30,130 --> 00:19:33,640
‫And now we can compile this and look at that.

260
00:19:33,640 --> 00:19:35,380
‫We have a successful compile.

261
00:19:35,380 --> 00:19:37,180
‫So let's hop back into the editor.

262
00:19:37,180 --> 00:19:40,690
‫And here in the editor, why don't we go ahead and test out death?

263
00:19:40,690 --> 00:19:45,790
‫Let's see if I can destroy some of these tanks before becoming destroyed myself.

264
00:19:45,790 --> 00:19:47,680
‫That's going to be kind of a challenge.

265
00:19:47,710 --> 00:19:48,670
‫Oh, there's one.

266
00:19:48,670 --> 00:19:52,030
‫I killed one of them and I got the second one.

267
00:19:52,030 --> 00:19:53,230
‫Oh, and I died.

268
00:19:53,650 --> 00:20:01,840
‫So you can see that this game is a lot more fun now that we've added death and destruction to our ponds.

269
00:20:01,840 --> 00:20:03,550
‫So this is great.

270
00:20:03,850 --> 00:20:11,050
‫Okay, so what I want you to do is give yourself a huge pat on the back, because in this video we handled

271
00:20:11,050 --> 00:20:18,010
‫Actor Death, which involves quite a bit of interaction between these classes in our game.

272
00:20:18,100 --> 00:20:24,370
‫Now the way death is implemented is that the pond simply disappears, which means we still need a few

273
00:20:24,370 --> 00:20:24,940
‫things.

274
00:20:25,030 --> 00:20:26,890
‫We need win lose conditions.

275
00:20:26,890 --> 00:20:30,490
‫We need a way to show the player that they've won or lost the game.

276
00:20:30,490 --> 00:20:33,220
‫And we also need those special effects.

277
00:20:33,340 --> 00:20:36,430
‫We need some sounds, we need some explosions.

278
00:20:36,430 --> 00:20:39,520
‫Those things are going to come very, very soon.

279
00:20:39,520 --> 00:20:41,170
‫So congratulations.

280
00:20:41,170 --> 00:20:46,570
‫You've already come a long way and there are only a few steps left to go.

281
00:20:46,600 --> 00:20:48,310
‫I'll see you in the next video.

