﻿1
00:00:04,460 --> 00:00:05,240
‫Hello and welcome.

2
00:00:05,240 --> 00:00:10,250
‫In this lecture, we're going to be creating a killer mobile game mode, which is going to be just one

3
00:00:10,250 --> 00:00:17,270
‫of the possible game modes that we can create due to having a virtual -- killed method that could

4
00:00:17,270 --> 00:00:19,940
‫be called on any of the game modes that we want.

5
00:00:19,970 --> 00:00:24,560
‫Let's dive in and see how we're going to implement this virtual method.

6
00:00:25,540 --> 00:00:28,640
‫So we would like our game to be able to end.

7
00:00:28,660 --> 00:00:29,760
‫What does it mean for a game to end?

8
00:00:29,770 --> 00:00:34,990
‫It means that we go into some sort of state where we are the one or we've lost.

9
00:00:34,990 --> 00:00:37,240
‫We inform the player using some UI.

10
00:00:37,270 --> 00:00:40,810
‫We give them the option to maybe restart and play it again.

11
00:00:41,050 --> 00:00:43,020
‫Something along those lines.

12
00:00:43,030 --> 00:00:46,900
‫Now the classes involved with this typically are a game mode.

13
00:00:46,900 --> 00:00:52,420
‫The game mode is responsible for deciding rules about the game, such as who won and who lost.

14
00:00:52,780 --> 00:00:56,470
‫And for that, we're going to need to know who is being killed.

15
00:00:56,470 --> 00:01:02,500
‫So we're going to have this virtual method here called Pawn Killed, which will be called from our shooter

16
00:01:02,500 --> 00:01:09,370
‫pawn when it dies, whether or not it is the AI or it is the player that is doing the dying.

17
00:01:10,360 --> 00:01:15,310
‫And furthermore, I want to add a little complication here, which is that we'll have different game

18
00:01:15,310 --> 00:01:18,550
‫modes derived from our main shooter game mode.

19
00:01:18,550 --> 00:01:20,320
‫They will implement that game mode.

20
00:01:20,320 --> 00:01:21,580
‫That's what the arrow means here.

21
00:01:21,580 --> 00:01:25,840
‫It's often a little bit counterintuitive the way the arrow goes, but kill them all.

22
00:01:25,840 --> 00:01:33,310
‫Game mode inherits from the shooter game mode and it overrides pawn killed in order to count up and

23
00:01:33,310 --> 00:01:35,770
‫decide differently on the rules of the game.

24
00:01:35,770 --> 00:01:41,980
‫So that's why I want to put a virtual pawn killed method over in the parent shooter game mode and then

25
00:01:42,130 --> 00:01:48,130
‫implement or override it again in the kill all game mode, which is going to be the game mode that we're

26
00:01:48,130 --> 00:01:49,570
‫implementing for ourselves.

27
00:01:49,570 --> 00:01:54,490
‫And you might choose to do different game modes where maybe you just want to kill a certain amount of

28
00:01:54,490 --> 00:01:58,450
‫the enemies in the level rather than all of them or something along those lines.

29
00:01:58,450 --> 00:02:00,670
‫Maybe a capture the flag, something different.

30
00:02:01,900 --> 00:02:08,560
‫But basically what's going to happen is the shooter -- is going to find the game mode that's got the

31
00:02:08,560 --> 00:02:13,060
‫type shooter game mode and it's going to call it's -- killed.

32
00:02:13,060 --> 00:02:19,060
‫And then depending on whatever implementation there's actually there, it's going to go through to the

33
00:02:19,060 --> 00:02:21,250
‫implementation via the override.

34
00:02:21,910 --> 00:02:28,390
‫Now, another complication here is that our UI logic and restarting logic is really something that should

35
00:02:28,390 --> 00:02:35,200
‫happen in the player controller UI generally being the purview of the player rather than something global

36
00:02:35,200 --> 00:02:36,310
‫like the game mode.

37
00:02:36,340 --> 00:02:42,850
‫This is especially true in games that are multiplayer because the game mode doesn't actually exist on

38
00:02:42,850 --> 00:02:45,160
‫the player's machine, it only exists on the server.

39
00:02:45,160 --> 00:02:49,270
‫So any UI stuff should be going on in the player controller.

40
00:02:49,540 --> 00:02:52,690
‫That's a complication we don't need to worry about because this is not a multiplayer game, but it's

41
00:02:52,690 --> 00:02:57,430
‫still good to use the classes for what they're expected to be used for in Unreal.

42
00:02:57,880 --> 00:03:04,750
‫So the player controller, the actual root player controller class has a virtual method called game

43
00:03:04,750 --> 00:03:12,610
‫has ended specifically for this purpose so that the game mode can call this method and we can implement

44
00:03:12,610 --> 00:03:17,770
‫it in our own shooter player controller to do UI, restarting, all that sort of stuff.

45
00:03:17,830 --> 00:03:23,590
‫But we'll need to be calling it from our game mode when we have decided that the game is over.

46
00:03:23,590 --> 00:03:28,270
‫So we'll call the virtual game has ended on the root player controller.

47
00:03:28,390 --> 00:03:33,910
‫And then because that root player controller is actually a shooter, player controller will end up diverting

48
00:03:33,910 --> 00:03:35,290
‫back and calling.

49
00:03:35,290 --> 00:03:36,130
‫This game has ended.

50
00:03:36,130 --> 00:03:42,040
‫So it seems like a circuitous route we're going to be calling from our shooter pawn via the shooter

51
00:03:42,040 --> 00:03:46,570
‫game mode to the killer more game mode to the player controller to the shooter player controller.

52
00:03:46,570 --> 00:03:52,360
‫But this allows us lots of flexibility in terms of saying, well, we can mix and match different player

53
00:03:52,360 --> 00:03:55,900
‫controllers that will show UI in different ways, in different levels.

54
00:03:55,900 --> 00:04:00,130
‫We can mix and match different game modes that are going to work in different ways, and that's the

55
00:04:00,130 --> 00:04:02,260
‫reason for me architecting it in this way.

56
00:04:02,260 --> 00:04:07,750
‫It's a little bit overkill for our project, but it shows you how this could extend to other projects

57
00:04:07,750 --> 00:04:11,970
‫with Capture the Flag game modes and different sorts of player controller.

58
00:04:11,980 --> 00:04:14,500
‫So let's have a go at implementing it.

59
00:04:14,530 --> 00:04:18,040
‫We're going to go and first of all, find a route game mode.

60
00:04:18,040 --> 00:04:22,330
‫There's already one created because I started from a C++ project.

61
00:04:22,330 --> 00:04:28,120
‫We've got this simple shooter game mode base and what I want to do here is create a public function

62
00:04:28,120 --> 00:04:35,800
‫which is going to return void and it's going to be -- killed and we're going to have to pass in the

63
00:04:35,830 --> 00:04:37,480
‫-- that was killed here.

64
00:04:37,480 --> 00:04:42,400
‫So it's going to be a -- star called -- killed like so.

65
00:04:42,400 --> 00:04:46,720
‫And then at the beginning, we're going to make this a virtual method and we're going to go ahead and

66
00:04:46,720 --> 00:04:50,770
‫create a basic implementation that essentially does nothing in here.

67
00:04:50,770 --> 00:04:52,930
‫Then we're going to create a subclass.

68
00:04:52,930 --> 00:05:00,010
‫So new C++ class, going to show all classes and we're going to look for our shooter, simple shooter

69
00:05:00,010 --> 00:05:02,230
‫game mode base as our base class.

70
00:05:02,230 --> 00:05:12,010
‫And we're going to call this the kill em all game mode like so and go ahead and create that class.

71
00:05:12,010 --> 00:05:18,100
‫Then when that has compiled, I want to just switch over for a second and go to our shooter character.

72
00:05:18,130 --> 00:05:23,620
‫CP And you can see in here we've got our is dead in the take damage method.

73
00:05:23,830 --> 00:05:30,490
‫Now if this is dead, what I want to be doing is getting hold of our game mode and calling the --

74
00:05:30,490 --> 00:05:31,180
‫killed.

75
00:05:31,210 --> 00:05:38,470
‫So the way we do this is we start with calling to get world in order to get the game mode, then it's

76
00:05:38,470 --> 00:05:40,690
‫get auth game mode.

77
00:05:40,690 --> 00:05:46,750
‫And then what we want to do is for this game mode to be of the correct type, which is the simple,

78
00:05:46,750 --> 00:05:52,150
‫the root one, the simple shooter game mode that allows us to then switch out this character, use it

79
00:05:52,150 --> 00:05:54,910
‫with different game modes such as capture the flag game modes.

80
00:05:55,060 --> 00:06:01,540
‫So the way we can do this, we can use the angle brackets right in the get all game mode right here,

81
00:06:01,540 --> 00:06:07,900
‫and we're going to do a simple shooter game mode and we're going to need to include that at the top.

82
00:06:08,320 --> 00:06:15,270
‫So hash include simple shooter game mode base go.

83
00:06:15,550 --> 00:06:18,070
‫So I didn't quite get the whole class name right?

84
00:06:18,070 --> 00:06:18,700
‫I think so.

85
00:06:18,700 --> 00:06:22,180
‫It's going to be a simple shooter game mode base.

86
00:06:22,360 --> 00:06:23,710
‫That's what we're trying to get.

87
00:06:24,130 --> 00:06:29,290
‫And we can go ahead and store that in a variable pointer, let's call it the game mode.

88
00:06:29,290 --> 00:06:35,860
‫And then what we want to do is on this new line, we probably want to check that we have got this and

89
00:06:35,860 --> 00:06:36,790
‫it's not a null pointer.

90
00:06:36,790 --> 00:06:40,630
‫So game mode is not equal to a null pointer.

91
00:06:40,630 --> 00:06:47,680
‫And then if it is not equal to a null pointer, that is where we want to call game mode arrow pawn killed

92
00:06:47,680 --> 00:06:50,590
‫and the pawn killed is this like so?

93
00:06:50,590 --> 00:06:55,150
‫So now the game mode is aware of a pawn having been killed.

94
00:06:55,170 --> 00:07:00,460
‫Little mini challenge for you to override the kill them all game mode so that you can.

95
00:07:00,580 --> 00:07:06,880
‫Log out when the -- is killed and set that as the default game mode in your map.

96
00:07:07,210 --> 00:07:09,680
‫So hopefully you had a go at that little mini challenge.

97
00:07:09,700 --> 00:07:11,800
‫We're going to go ahead and implement.

98
00:07:11,800 --> 00:07:17,740
‫So I'm going to do this by copying the public section of our simple shooter game mode base, and it's

99
00:07:17,740 --> 00:07:19,540
‫hard to keep track of all these things.

100
00:07:19,540 --> 00:07:24,070
‫Then we're going to go over to our kill them all game mode base, which inherits from it.

101
00:07:24,310 --> 00:07:31,360
‫And we're going to paste in the virtual method and we're going to add the override keyword to make sure

102
00:07:31,360 --> 00:07:33,850
‫that we're overriding this method correctly.

103
00:07:34,730 --> 00:07:39,620
‫Then I'm going to create an implementation over in the C++ for our KML game mode base.

104
00:07:40,100 --> 00:07:42,980
‫This is where we should be getting that log message.

105
00:07:42,980 --> 00:07:48,430
‫And just to be super careful, we know there's nothing in the implementation, but you never know.

106
00:07:48,440 --> 00:07:52,130
‫Things might change later on and we might get bit in the bomb.

107
00:07:52,140 --> 00:07:55,250
‫So we want to do a pawn killed.

108
00:07:56,310 --> 00:07:59,160
‫Super -- killed with the -- killed.

109
00:07:59,190 --> 00:08:00,060
‫Makes sense.

110
00:08:00,330 --> 00:08:09,630
‫And then we want to do a you log in here basically saying that a -- was killed and we can see if that

111
00:08:09,630 --> 00:08:17,940
‫works by going over into Unreal and compiling, then going to the blueprints item on the toolbar and

112
00:08:17,940 --> 00:08:23,250
‫selecting in the project settings that our default game mode we want to be.

113
00:08:23,250 --> 00:08:29,040
‫If we select game mode, base class, we want it to be the KML based game mode.

114
00:08:29,040 --> 00:08:31,770
‫Basically, go ahead and do that.

115
00:08:31,770 --> 00:08:35,640
‫In fact, that's not quite what we want us to do if we go and select.

116
00:08:35,640 --> 00:08:44,160
‫We wanted it actually to be a blueprint child of that and we've already got a blueprint child that has

117
00:08:44,160 --> 00:08:45,060
‫a lot of things set up.

118
00:08:45,060 --> 00:08:47,820
‫So let's do a re parenting job there.

119
00:08:48,390 --> 00:08:54,090
‫We'll go to the roots, we'll find the BP shooter game mode, which we've got here.

120
00:08:54,240 --> 00:09:02,790
‫We're going to rename this BP, kill em all game mode, and then we can open that up, dock the window,

121
00:09:02,790 --> 00:09:10,500
‫open the full blueprint editor, go to the class settings and change the parent to the KML game mode,

122
00:09:10,500 --> 00:09:11,940
‫C++ basically.

123
00:09:12,030 --> 00:09:18,030
‫And that way we should be running the correct code if we go to our message to our output log and hit

124
00:09:18,030 --> 00:09:25,740
‫play and then kill off a character, a we have a problem does not appear to have the right set up.

125
00:09:25,740 --> 00:09:35,010
‫So if we go back to our class defaults and change up the default -- class to being the BP shooter

126
00:09:35,010 --> 00:09:36,900
‫character, that should be correct.

127
00:09:36,900 --> 00:09:39,330
‫Save and compile just in case it got that wrong.

128
00:09:39,330 --> 00:09:42,000
‫And then check my blueprints drop down here.

129
00:09:42,000 --> 00:09:44,700
‫It's selected the KML game mode, the C++ one.

130
00:09:44,700 --> 00:09:49,530
‫So we actually want to choose the blueprint one in here and go ahead and hit play.

131
00:09:49,530 --> 00:09:50,850
‫Now we've got our pawn.

132
00:09:50,850 --> 00:09:57,330
‫We can go ahead and kill this guy and you can see that a pawn was killed is printed log message.

133
00:09:57,330 --> 00:10:00,090
‫So that is working fantastically.

134
00:10:00,240 --> 00:10:05,580
‫Now in the next lecture, we're going to be looking at the second part of this, which is calling game

135
00:10:05,580 --> 00:10:12,870
‫has ended when we actually do want to end the game and to be able to restart from there on.

136
00:10:12,960 --> 00:10:15,930
‫So I will see you in that lecture.

