‫Hello and welcome back.
‫Now, we've already created the ability to handle death for the tank and tower, and we saw that this
‫involved some extra steps with our tank since we accessed the player controller to disable input and
‫disable showing the mouse cursor.
‫Now we'd like to have our own custom player controller class so that we can add functionality to it
‫that will handle this for us.
‫And then we'd like to create a blueprint based on this class so that we can access some of the exposed
‫variables on the player controller such as which mouse cursor to show once we actually start showing
‫the mouse cursor.
‫So we're going to create a player controller class and add enabling and disabling input functionality.
‫And then we're going to create a blueprint and set the mouse cursor type in blueprints.
‫Now creating this class is something you know how to do.
‫So you're going to create a player controller class for your challenge, create a new C++ class, and
‫choose player controller as the parent class.
‫Call this tune tanks, player controller or something appropriate like that.
‫And once you're done, create a blueprint based on this class.
‫Now, once you have the blueprint, you can assign this as the default player controller in the game
‫mode blueprint.
‫Do this in the game mode, blueprint itself.
‫Pause the video and create the player controller class for the tank now.
‫Okay.
‫So I'm back in the editor.
‫I'm going to right click click new C++ class and scroll down and I'll see that player controller is
‫an option here.
‫So I'm going to select player controller and name my new player controller tune tanks.
‫Player, controller and click create class.
‫And here I have my new player controller class.
‫Now the next step is to create a blueprint based on this.
‫So I'm back in the editor and I didn't tell you to do this, but I'm going to create a new folder here
‫in my blueprints folder called Player Controller.
‫And if you'd like the same folder structure, you can create this folder now if you haven't already
‫done so and then move your player controller blueprint into this.
‫If you don't know how to move a blueprint from one folder to another, it's quite simple.
‫You go to the folder that contains the blueprint, click and drag into the correct folder and click
‫move here.
‫Now, I don't want to move my projectile to this folder, so I'm just going to click here in the content
‫browser to cancel that action.
‫So now I have a player controller folder.
‫I'm going to right click and click Blueprint Class and in this search I'm going to look for toon tanks,
‫player controller and select that class and click Select.
‫Now I can call this beep underscore toon tanks player controller.
‫So I now have a player controller.
‫Now I need to set this as the default player controller.
‫So I'm going to go to the game mode folder, open beep, tune tanks, game mode and open the full blueprint.
‫Editor And here I see player controller class.
‫I'm going to click the dropdown and select BP tune tanks, player controller and compile and save and
‫close out of that.
‫So now we have the custom player controller class.
‫We're ready to add some functionality to this.
‫So what I'd like is a function here that can set the player enabled state, whether or not the player
‫is enabled to add input that will move the tank.
‫Now I plan on calling this from the game mode when the actor dies.
‫So I'm going to make a public section here and the function is going to be void.
‫And I'm simply going to call this set player enabled state, which can take a boolean called B player
‫enabled.
‫This way, if we call this function, we can either pass in true if we'd like the player to be enabled
‫or false if we'd like it to be disabled.
‫So let's implement this function in tune tanks, player, controller.
‫CP So here's my function and of course I need the class name here.
‫So it's going to be a tune tanks, player, controller, and there's the scope resolution operator.
‫Now, this function is going to be quite simple.
‫It's going to check the value of B player enabled, and we can do that with a simple if check.
‫So I'm going to say if B player enabled and I'd like to access the pawn and enable or disable input
‫and the way to access the pawn that this player controller is possessing is to use the function, get
‫pawn.
‫This returns and a pawn and the pawn class has the function.
‫Enable input and enable input as we've seen requires a player controller so we can pass in this.
‫Now I'm getting the red squiggles because we need to include that pawn class type and we can easily
‫see the include for the pawn by either going to the unreal engine documentation for a pawn, or we could
‫simply go to our base pawn class which inherits from a pawn.
‫And because it inherits from a pawn, we've seen that it needs to include the pawn header there so I
‫can copy that include it's game framework, a slash pawn.
‫So back in tune tanks player controller.
‫I can paste that include here at the top to get rid of those red squiggles.
‫So this takes care of the case when B player enabled is true, but we also need an LS case here.
‫In the LS case we're going to call get pawn and there's a function just like enable input that is designed
‫to disable input and it's called, as you might guess, disable input.
‫And this also requires a player controller for which we will pass in this.
‫Now the player controller has that be show mouse cursor and we're going to set that as well.
‫And we'd like to set it based on whether or not the player should be enabled.
‫So whatever the Boolean value of B player enabled, we're going to set B show mouse cursor to that value.
‫So we're going to say B sho mouse cursor equals B player enabled.
‫Now we haven't shown the mouse cursor yet.
‫We're going to get to that part.
‫We'd actually like to see the mouse cursor while we're playing the game so we know where our tank is
‫aiming.
‫So we'll get to that soon.
‫But for now we have this nice function in the player controller and we'd like to call this function
‫from the game mode now to show you what I mean.
‫I'm going back to game mode and here's the actor died function and you'll see that we're disabling input
‫and we're setting b show mouse cursor here.
‫So the reason I'd like to have a.
‫Function on the player controller so that we can simply call that function passing in a boolean value.
‫In this case, we'd pass in false so that we'd get that disable input function called and B so mouse
‫cursor would be set to false.
‫So we can simply call that function here now rather than calling tank get player controller which returns
‫a player controller.
‫I'd like to have a pointer variable that allows us to access that player controller.
‫So here in tune tanks game modes, I'm going to add a private variable.
‫I'm going to forward declare it and it's going to be of type A tune tanks, player, controller, that's
‫a pointer.
‫And I'm going to call this tune Tank's Player Controller and I can set this here in tune tanks game
‫mode and begin play using gameplay statics.
‫Now if you are wondering if game play statics had a get player controller function, you were right.
‫This is one of those handy static functions that requires a world context object and a player index
‫so we can go ahead and copy the include for gameplay statics and call this here in Begin Play.
‫So I see at the top here, I already have gameplay statics, that's because we're using it already here
‫and begin play to call get player --.
‫We're going to do the same thing here to set the player controller pointer.
‫Now this is something you should know how to do.
‫So why don't you pause the video and do a little mini challenge here and just set the value of tune
‫tanks, player controller.
‫Okay.
‫So we're going to say tune tanks, player, controller, and we're setting it equal to the result of
‫you gameplay statics get player controller and we know the world context object can be this and the
‫player index is not nine but zero.
‫And of course we know that this returns a player controller and not a tune tanks player controller.
‫So just like we did with Tank here, we're going to cast.
‫So I'm going to say cast to a tune tanks player controller and we're casting the result of get player
‫controller.
‫So now after Begin Play, we will have the tune tanks, player controller.
‫And now we can come up here and instead of getting the player controller using get player controller
‫directly from the tank, we can check to make sure our variable tune tanks player controller is valid
‫and then we can call that function we made.
‫Let's go back and look at it.
‫It's called set player enabled state and here in the game mode we'd like to disable input and stop showing
‫the cursor, which means we're going to pass in false for this.
‫So we're going to say tune tanks, player, controller, set player enabled state and we're passing
‫in false for this and we're using tune tanks, player controller, which means we need to include tune
‫tanks, player controller.
‫So here at the top we're going to include tune tanks, player controller.
‫And now we have this type defined OC.
‫Let's go ahead and compile this.
‫And the last thing we'll do before we wrap this up is go into our player controller blueprint and I'd
‫like you to scroll down to the mouse interface section and you'll see that it says Default Mouse Cursor.
‫Now we can click the dropdown and there are a number of different cursors to choose from.
‫And I'm going to choose Crosshairs.
‫Now, we're not showing the mouse cursor yet, but once we start the game we're going to show the cursor.
‫And when we do, I like it to be crosshairs instead of the default white arrow that we always see when
‫we look at the mouse cursor.
‫So set default mouse cursor to crosshairs and we'll be able to see those crosshairs once we actually
‫enable the mouse cursor.
‫So in summary, we created a custom player controller class and we're using that to enable or disable
‫input with a function that we placed on that class.
‫And we're also using that function to show the mouse cursor or hide the mouse cursor based on the Boolean
‫passed in.
‫And in the blueprint that we created, we set the mouse cursor type and we're going to see very soon
‫what that crosshairs mouse cursor looks like when we start showing the mouse cursor when the game starts.
‫So great job.
‫We now have this player controller and we're ready to continue implementing game functionality.
‫So I'll see you in the next video.