♪♪♪
(Wes Bunn) Hey everyone; welcome back. So in the previous video, we set up the functionality
for our Character's movement. We assigned our MoveForward and our MoveRight Events,
which will drive our Character's movement in game. We also set up our Mouse Input to
control our camera, so turning and moving the camera Left and Right, moving it Up and
Down as well with our LookUp Event here. We also set up the ability to jump for our Character.
So our Character, in essence, is ready to be used in our game and should be playable.
In this video, we will set up the Game Mode which we will use to assign our game's Default
Classes and more specifically, the Default Pawn Class which is the Pawn that is used
by players, essentially. That is what I am getting at. So let's continue. One thing I
wanted to mention that I didn't do in the previous video is it is always a good habit
whenever working with Blueprints to Compile and Save your Blueprints often. So I just
wanted to point that out really quickly. So let's, if you haven't already, go ahead and click the
Compile button up here to finalize our Blueprint script. It says we are good to go.
Then go ahead and save, to make sure we save all of our changes. So with that, let's close the
Character Blueprint as we are not going to be working in it at the
moment. So let's close it. Inside the Content Browser, I am going to Right-click in an empty
space and create a new Blueprint. So let's go up to Blueprint Class here. It is going
to give us the Pick Parent Class dialogue box; go ahead and select the Game Mode. You
can see it says, "Game Mode defines the game being played, its rules, scoring, and other
facets of the game type." So select Game Mode. It is going to create a new asset for us and
ask us to enter a name, so let's go ahead and do that. Let's just call it "MyGame", like
so. Then, Double-click on it to open it up. Now
when you open it... Mine opened up off-screen actually; let me bring it onscreen here. (Laughter)
When you open it, you will be presented it with a very similar looking interface to what
we did inside the Character Blueprint. We will be on the Viewport tab. Now, 99.9% of
the time you are not going to need to add Components like we did with our Character
Blueprint when working inside of a Game Mode. For our purposes, all we are really focused
on is the Class Defaults. So make sure that Class Defaults is selected. Then over in the
Details panel over here on the right towards the bottom, you can see we have a bunch of
settings that we are not going to worry about right now. All we are really worried about
are the Class Defaults and the Classes. So you can see at the top, there is a setting
for Default Pawn Class. Currently it is using a DefaultPawn that comes default with the
editor. We want to change this to use our own. So go ahead and click the drop down and
find that CharacterBP, so the Character Blueprint that we created. So select that. Again, Compile
and Save from the Toolbar. So, Compile and Save. Then, close the Game Mode Blueprint. That
is all we need to do for now. So once we have closed that, we have our Game
Mode set up but we haven't told our project to use it yet. There are a couple different
ways that we could do this. Let's go to Settings first from the Toolbar up here at the very
top. At the very top, we have World Settings and Project Settings. Let's go to World Settings
first. So select World Settings. Over in the far right over int he Details panel, a new
World Settings panel opens. This allows us to change various settings per level. So right
now, there is a Game Mode section and there is a GameMode Override currently set to None.
This will override whatever the default Game Mode is that is currently assigned to this project as a
whole, which we will do in a moment. This will override that for this particular level.
So for the sake of practice, let's just go ahead and do that. We are going to set it
up as the default as well, but we will do it here as well. So click the drop down; go
ahead and choose the MyGame Game Mode Blueprint that we just created a moment ago. You can
verify that your settings have been applied. Go click the arrow here next to Selected GameMode
and you can see our Default Pawn Class is set to use our CharacterBP. Now this does
this for this level. If we were to open another level, it would use whatever the Default GameMode
is and its setting. So let's set that Default GameMode really quickly. Let's go back up
to Settings. This time we are going to choose Project Settings. That is going to open
the Project Settings window. Let me pull it off so you can see it. Not dock it, but pull
it off. Let's see. So, we are going to go into the Maps & Modes section under Project.
You can see towards the bottom there is a Default GameMode section. Yours may not be
expanded; I may have been doing something in between videos where mine was expanded.
(Laughter) This is the only section we are focused on right now, so the Default GameMode
is currently set to use the Engine's Default GameMode. Let's change that to our Game Mode,
so we are going to use MyGame here. Again, we can verify that our setting has taken
effect, which it has. Because we are writing to the DefaultEngine.ini, which is currently
writable, we don't need to explicitly Save, our changes have been saved for us automatically.
So, let's close the Project Settings now. Inside the Level Viewport here, we are ready to Play
and test. But we have very little room to move around, so really quickly what I am going
to do is select this floor piece here. Just Left-click to select it. I am going to hit
R on my keyboard to go into Scale Mode. I am going to grab this green widget and move
it in this direction to give us a little bit of a platform. I am going to grab the red
one now and drag it toward the left, like so. Then I am going to press W to enter Translation Mode,
and just kind of center this up by grabbing this green arrow; something like this. It
just gives us a little bit more room to run around on our floor here. Okay with that,
I think we are ready to test it now. Let's see; hopefully everything should work. Let's
hit Play from the main Toolbar up here. Our Character spawns in. We can control our mouse
by using the mouse. (Laughter) Or, control our camera by using the mouse, excuse me.
We can also press W to run around, and S, and D, and A. We can jump with our Character as
well. We can control the camera, like I mentioned. The camera will follow us around, so everything
is looking good. Everything is working as expected. So before we wrap this video, there
is one other thing that I wanted to cover really quickly as we are about 7 minutes in
and this would have been a short video otherwise: camera control. So right now if I move the
mouse Up, my camera pitches up. If I move my mouse Down, the camera kind of pitches
down. If you would like to invert your controls, you could do that. If I hit Esc here, you
could do that inside of the Project Settings > Input > Engine, all
the way down on our LookUp and Mouse Y settings. I believe I mentioned this as well as we were
setting these up. If I set this to 1.0, that will essentially invert our controls. So moving
Up would actually move me down and moving Down would actually move me up. So if you
prefer using those controls, you could set that in here. But I figured I would show you
a quick and easy way to kind of have a toggle for this inside the editor if you would like
to change it inside the editor and play with those settings. So let me close the Project
Settings. Traditionally, you would probably have a Pause menu where you could set this
in game so those changes take effect. But what we are going to do is just create a simple
way of testing it inside the editor so that inside the Details panel here, I could click
an option and change that setting without having to go into the Project Settings and
change it. So let's do that. To do that, let's open the Character Blueprint folder here.
So we are going to open that up. Double-click on it to open it up. What we are looking for
is let's find our Mouse Input section here. All we are really worried about is this LookUp
section. We don't really care about Turn because we are not going to invert those, although
you could if you would like using this same method. So let's focus on these for a second.
I am going to Mouse Wheel In and I am going to Right-Click on this executable pin here.
Just Right-click and select Break Link to Add Controller Pitch. So that will break the
connection. I am going to do the same thing for Axis Value. So now that those are broken,
we can add a check here to see if our LookUp Axis Event here should be inverted. So one
other thing to mention really quickly with comments; this is pretty handy. With comments
you can move a comment block so you don't have to actually select all nodes, like so
and then move the nodes. With comments, you can move them as a single unit like this,
so that is kind of handy as well as making comments. So I am going to move this down
just a little bit and give us a little bit more room. I am going to stretch out our comment
block just a little bit. Move this Add Controller Pitch Input over just a little bit. What
we are going to do is run a true or false check to see if this should be inverted. So
let's hold B on our keyboard and Left-click in the graph. That is going to create a Branch
node for us and that is going to give us that True or False. So let's connect the executable
here; Left-click and drag to the Branch. Then for the True, we will connect to our current
Add Controller Pitch Input, and move it up like so. I am going to hit Ctrl+C and Ctrl+V
to copy that because we are going to need two instances of this. Then, we are going
to connect the False, like so. Let's stretch our comment box down so it is encompassing
it. Now for the False, we are currently going to grab our Axis Value here and just plug
that right in because that is our current setting; we don't want to change it. But for
True if we want to invert it, what we are going to do is let's drag off our Axis Value
again. To get that inverted value, all we are going to do is multiply. So let's drag
off and search for "multiply". We are going to do Float * Float. What we are going to
do is for that Value here, let's change this to -1.0. That will invert whatever our Value
is here. So now we can plug that into our Value for our Controller Pitch Input. Now,
we still need to add our variable here that is going to be either True or False. To do
that, let's Right-click on the Condition here and Promote to Variable. Inside the MyBlueprint
window, it is asking us to name this new variable that we added. So let's just call this "Invert
Mouse Control". So Invert Mouse Control. I am going to move this up in the graph as well, so
we can see it. The next thing that we will do to finish up inside the MyBlueprint window,
you can see there is a little Closed Eye icon here. If we click this, the Eye will open
and it will be yellow. This will let us edit this variable inside the Level Editor. So
it will become a publicly editable variable that we can change inside the editor. It is
currently yellow because it is missing a tooltip, so when I mouse over it is telling me what
it does in the editor. So let's add one really quickly. So go ahead and select it. Over in
the Details panel in the upper right, there is an option for Tooltip. Go ahead and enter
a tooltip for it. So you can say, "This inverts the mouse controls," like so. When you hit
Enter, you can see that the Eye has been changed to green letting us know that we now have a tooltip
for it as well. So let's Compile and Save. Then, let's close the Character Blueprint.
Okay, the final thing that we need to do before we wrap up this video is test this. The way
we can test this actually is inside the Content Browser, let's grab our CharacterBP here.
Let's just Left-click and drag him into the level, like so. Now what we have is a PlayerStart
and our CharacterBP, but what we want to do is automatically possess or take control of
this Character when the game begins. So to do that, we can kill our PlayerStart. So go
ahead and select our PlayerStart and hit Delete as we are going to be spawning in as this
particular Character here. So I am going to move him over just a little bit so he is centered
up. With him still selected over in the Details panel if we scroll down a little bit under
the Default section, there is our new Boolean variable (Invert Mouse Control) that we can toggle on and off to
invert our controls. So if I leave it checked and I hit Play in the editor, we are going
to spawn in as a new Character first of all. There is one other thing I forgot to do. (Laughter)
Let's hit Stop really quickly. We need to tell this CharacterBP here that we automatically
want to possess it, so let's do that really quickly. Let's search inside the Details panel
here; let's search for "possess". You can see it says Auto Possess Player. Currently, it
is disabled. We want to enable this and it is going to ask us for a Player to Possess.
By default in a single player game, you are always going to be Player 0. So go ahead and
select Player 0. This will let this Character know that we want to possess it with Player
0. So now if we hit Play in the editor, we will possess that Character. As we move the
mouse Down, we are looking up. As I move the mouse Up, we are looking down. If I hit Esc,
go back to the Details panel and I clear our search, scroll down, find our Invert Mouse Controls and
I uncheck that, now when I Play in the editor and I move the mouse Up, I am moving up. When
I move the mouse Down, I am looking down. So we are set. That is actually going to cause
us to pause here. In the next video..., well actually let me really quickly recap what
we have done here. We have created our Game Mode. We have assigned a Default Pawn to use
our PlayerCharacter here. We also added a toggle to invert our mouse. So we are set
to move around. We need to do one more thing regarding our controls; that is set up the
ability to control the camera with the Gamepad Right Thumbstick because currently only our
Gamepad Left Thumbstick works. If you recall over in the Edit > Project Settings > Input,
we have assigned Gamepad Left Thumbstick Y-Axis and Gamepad Left Thumbstick X-Axis to our
MoveForward and MoveRight. So whenever we call MoveForward and MoveRight, the Gamepad
Left Thumbstick will automatically work. We don't have to do anything extra; those just
come along for the ride. It is that Gamepad Right Thumbstick that we have to worry about
and set up inputs for, which we haven't done. We have only done our Turn and we have only
done our LookUp. In the next video, we will do our TurnRate and our LookUpRate so that
we can get functionality with our Gamepad Right Thumbstick, as well as adding touch controls.
We don't have touch controls right now either, so we will do that in the next video.
So thank you guys for watching and we will see you in that video.
♪♪♪