‫Hello and welcome.
‫In this lecture, we're going to be creating a killer mobile game mode, which is going to be just one
‫of the possible game modes that we can create due to having a virtual -- killed method that could
‫be called on any of the game modes that we want.
‫Let's dive in and see how we're going to implement this virtual method.
‫So we would like our game to be able to end.
‫What does it mean for a game to end?
‫It means that we go into some sort of state where we are the one or we've lost.
‫We inform the player using some UI.
‫We give them the option to maybe restart and play it again.
‫Something along those lines.
‫Now the classes involved with this typically are a game mode.
‫The game mode is responsible for deciding rules about the game, such as who won and who lost.
‫And for that, we're going to need to know who is being killed.
‫So we're going to have this virtual method here called Pawn Killed, which will be called from our shooter
‫pawn when it dies, whether or not it is the AI or it is the player that is doing the dying.
‫And furthermore, I want to add a little complication here, which is that we'll have different game
‫modes derived from our main shooter game mode.
‫They will implement that game mode.
‫That's what the arrow means here.
‫It's often a little bit counterintuitive the way the arrow goes, but kill them all.
‫Game mode inherits from the shooter game mode and it overrides pawn killed in order to count up and
‫decide differently on the rules of the game.
‫So that's why I want to put a virtual pawn killed method over in the parent shooter game mode and then
‫implement or override it again in the kill all game mode, which is going to be the game mode that we're
‫implementing for ourselves.
‫And you might choose to do different game modes where maybe you just want to kill a certain amount of
‫the enemies in the level rather than all of them or something along those lines.
‫Maybe a capture the flag, something different.
‫But basically what's going to happen is the shooter -- is going to find the game mode that's got the
‫type shooter game mode and it's going to call it's -- killed.
‫And then depending on whatever implementation there's actually there, it's going to go through to the
‫implementation via the override.
‫Now, another complication here is that our UI logic and restarting logic is really something that should
‫happen in the player controller UI generally being the purview of the player rather than something global
‫like the game mode.
‫This is especially true in games that are multiplayer because the game mode doesn't actually exist on
‫the player's machine, it only exists on the server.
‫So any UI stuff should be going on in the player controller.
‫That's a complication we don't need to worry about because this is not a multiplayer game, but it's
‫still good to use the classes for what they're expected to be used for in Unreal.
‫So the player controller, the actual root player controller class has a virtual method called game
‫has ended specifically for this purpose so that the game mode can call this method and we can implement
‫it in our own shooter player controller to do UI, restarting, all that sort of stuff.
‫But we'll need to be calling it from our game mode when we have decided that the game is over.
‫So we'll call the virtual game has ended on the root player controller.
‫And then because that root player controller is actually a shooter, player controller will end up diverting
‫back and calling.
‫This game has ended.
‫So it seems like a circuitous route we're going to be calling from our shooter pawn via the shooter
‫game mode to the killer more game mode to the player controller to the shooter player controller.
‫But this allows us lots of flexibility in terms of saying, well, we can mix and match different player
‫controllers that will show UI in different ways, in different levels.
‫We can mix and match different game modes that are going to work in different ways, and that's the
‫reason for me architecting it in this way.
‫It's a little bit overkill for our project, but it shows you how this could extend to other projects
‫with Capture the Flag game modes and different sorts of player controller.
‫So let's have a go at implementing it.
‫We're going to go and first of all, find a route game mode.
‫There's already one created because I started from a C++ project.
‫We've got this simple shooter game mode base and what I want to do here is create a public function
‫which is going to return void and it's going to be -- killed and we're going to have to pass in the
‫-- that was killed here.
‫So it's going to be a -- star called -- killed like so.
‫And then at the beginning, we're going to make this a virtual method and we're going to go ahead and
‫create a basic implementation that essentially does nothing in here.
‫Then we're going to create a subclass.
‫So new C++ class, going to show all classes and we're going to look for our shooter, simple shooter
‫game mode base as our base class.
‫And we're going to call this the kill em all game mode like so and go ahead and create that class.
‫Then when that has compiled, I want to just switch over for a second and go to our shooter character.
‫CP And you can see in here we've got our is dead in the take damage method.
‫Now if this is dead, what I want to be doing is getting hold of our game mode and calling the --
‫killed.
‫So the way we do this is we start with calling to get world in order to get the game mode, then it's
‫get auth game mode.
‫And then what we want to do is for this game mode to be of the correct type, which is the simple,
‫the root one, the simple shooter game mode that allows us to then switch out this character, use it
‫with different game modes such as capture the flag game modes.
‫So the way we can do this, we can use the angle brackets right in the get all game mode right here,
‫and we're going to do a simple shooter game mode and we're going to need to include that at the top.
‫So hash include simple shooter game mode base go.
‫So I didn't quite get the whole class name right?
‫I think so.
‫It's going to be a simple shooter game mode base.
‫That's what we're trying to get.
‫And we can go ahead and store that in a variable pointer, let's call it the game mode.
‫And then what we want to do is on this new line, we probably want to check that we have got this and
‫it's not a null pointer.
‫So game mode is not equal to a null pointer.
‫And then if it is not equal to a null pointer, that is where we want to call game mode arrow pawn killed
‫and the pawn killed is this like so?
‫So now the game mode is aware of a pawn having been killed.
‫Little mini challenge for you to override the kill them all game mode so that you can.
‫Log out when the -- is killed and set that as the default game mode in your map.
‫So hopefully you had a go at that little mini challenge.
‫We're going to go ahead and implement.
‫So I'm going to do this by copying the public section of our simple shooter game mode base, and it's
‫hard to keep track of all these things.
‫Then we're going to go over to our kill them all game mode base, which inherits from it.
‫And we're going to paste in the virtual method and we're going to add the override keyword to make sure
‫that we're overriding this method correctly.
‫Then I'm going to create an implementation over in the C++ for our KML game mode base.
‫This is where we should be getting that log message.
‫And just to be super careful, we know there's nothing in the implementation, but you never know.
‫Things might change later on and we might get bit in the bomb.
‫So we want to do a pawn killed.
‫Super -- killed with the -- killed.
‫Makes sense.
‫And then we want to do a you log in here basically saying that a -- was killed and we can see if that
‫works by going over into Unreal and compiling, then going to the blueprints item on the toolbar and
‫selecting in the project settings that our default game mode we want to be.
‫If we select game mode, base class, we want it to be the KML based game mode.
‫Basically, go ahead and do that.
‫In fact, that's not quite what we want us to do if we go and select.
‫We wanted it actually to be a blueprint child of that and we've already got a blueprint child that has
‫a lot of things set up.
‫So let's do a re parenting job there.
‫We'll go to the roots, we'll find the BP shooter game mode, which we've got here.
‫We're going to rename this BP, kill em all game mode, and then we can open that up, dock the window,
‫open the full blueprint editor, go to the class settings and change the parent to the KML game mode,
‫C++ basically.
‫And that way we should be running the correct code if we go to our message to our output log and hit
‫play and then kill off a character, a we have a problem does not appear to have the right set up.
‫So if we go back to our class defaults and change up the default -- class to being the BP shooter
‫character, that should be correct.
‫Save and compile just in case it got that wrong.
‫And then check my blueprints drop down here.
‫It's selected the KML game mode, the C++ one.
‫So we actually want to choose the blueprint one in here and go ahead and hit play.
‫Now we've got our pawn.
‫We can go ahead and kill this guy and you can see that a pawn was killed is printed log message.
‫So that is working fantastically.
‫Now in the next lecture, we're going to be looking at the second part of this, which is calling game
‫has ended when we actually do want to end the game and to be able to restart from there on.
‫So I will see you in that lecture.