Create A Parasite Platformer Game In Unreal Engine Part 2: Game Modes, Player Character, And Setting Up The Input

Table of Contents

Create A Parasite Platformer Game In Unreal Engine Part 2: Game Modes, Player Character, And Setting Up The Input

Reading Time: 13 minutes
Level: Beginner
Version: Unreal Engine 4.26

Help Others Learn Game Development

Share on facebook
Share on twitter
Share on reddit
Share on linkedin

In part 1 of this tutorial series we created our game level and we learned about working with Actors inside the Level Editor.

In this part of the tutorial we are going to learn what are game modes, and we are going to create our Player Actor and make him move.

Where Is The Player In The Game

So far we just created the level for our game but we didn’t test the game out yet.
 
To test the game, we use the Toolbar tab that is above the Level Editor.
 
One of the buttons in the Toolbar is the Play button that we press to play the game in the editor:
 

As you can see, we have a first person view for the game and we can fly in the level.

We can pass through the level elements such as the Obstacle Walls, but we can fly above them to avoid them.

While we can control the movement, we don’t see the Player Actor that we are controlling. We can do that by using the Eject button:

The Player Actor that we are currently controlling is actually a Sphere object.

After we press the Eject button and we click on that Sphere object inside the Level Editor you will notice inside the World Outliner the name of that Sphere is DefaultPawn.

This is the default Player Actor that we can control when we create a new level and because of his limited functionality we can only use him to move around and check out the level.

Player Start Point

First, how do we set up a starting point where the Player Actor is going to spawn when the game starts.

The start point is determined with the Player Start Actor that comes by default with every level we create:

Which means, we can take the Player Start Actor and position it wherever we want in the level, and when the game runs this is where our Player Actor is going to be spawned.

Since we want the Player Actor to start at the beginning of the level right in front of the Start Wall Actor, we are going to set the Location values of the Player Start Actor to the following:

  • X = -9720
  • Y = 0
  • Z = 112
If you run the game now, you will see that the default Player Actor is spawned at the new position inside the level.
 

The Default Game Mode

We saw that the default Player Actor is a Sphere object called DefaultPawn.
 
The question here is, where is this defined?
 
To locate the default level settings, go to Edit -> Project Settings:
 
Img 2
Inside the Project Settings tab click on the Maps & Modes under the Project category on the left side:
 

Inside the Maps & Modes tab under Default Modes click on the drop down list on the left of the Selected Game Mode:

Img 4
When you do that, on the right side you will see a list of default classes that are used for the level:
 
Img 5 - 80%

The Default Pawn Class is set to DefaultPawn, which is the Player Actor that we saw in the game when we used the Eject button.

A Pawn object is a physical representation of a Player within the game world.

Basically a Pawn is an object that is placed in the level, same as the Actor, so if you refer to the game character as a Pawn or an Actor it’s one and the same thing.

The difference between them is that the an Actor is something you place in the game world, it can be a game character, a cube, a sphere and so on.

A Pawn is a type of Actor that can be possessed and receive input and we can control it.

But again, in my posts whenever I say Pawn or Actor that is referring to the same thing – a game object inside the level.

We also see other default classes like HUD Class, Player Controller Class and so on.

At the moment these are not important, we will talk about them when we want to use them with a practical example. For now, we are going to focus on the Default Pawn Class.

The Default Pawn Class is selected with the Default GameMode which currently is GameModeBase:

Img 6 - 80%
The GameMode is a class that we use to determine the default starting objects such as the Default Pawn Class.
 
Since we are using the default GameMode, we can’t edit the fields where we can select a custom Player Actor we created, or custom HUD, or any of the fields below the selected GameMode.
 
So to have our own custom Player Actor in the game, we need to create a custom GameMode as well.
 

Creating A Custom GameMode

Inside the Content root folder in the Content Browser tab Right Click -> New Folder and give it a name Blueprints.

Inside the Blueprints folder Right Click -> Blueprint Class:

Img 7
This will open a new window where we can create a new Blueprint for our game.
 
In the new window titled Pick Parent Class we are prompted to pick a parent class that we will inherit for the Blueprint that we will create.
 
The concept here is the same as the one we talked about in the C++ Inheritance lecture, so you can click on the link provided to refresh your knowledge if you need to.
 
Since we are going to create a custom GameMode, we can inherit from the Game Mode Base which is one of the classes from the list:
 
Img 8
The Game Mode Base is the top parent class for the GameMode class hierarchy. I say top parent class because we can also click on the drop down list where it says All Classes at the bottom of the Pick Parent Class window:
 
Img 9
From there, in the search bar type game mode and we can see the inheritance hierarchy of the classes:
 
Img 10

We are going to inherit from GameMode so select it, and then press the Select button at the bottom of the window.

This will create a new Blueprint in the folder where you right clicked to create a new Blueprint, in our case the Blueprint folder.

For the global GameMode I usually give the name for the Blueprint using the name of the project, so you can give that Blueprint the following name: BP_ParasitePlatformer_GameMode.

I said global GameMode above, becase we can also create GameModes for every level that we have, and we will see examples of that.

I always add BP in the beginning of the Blueprint name so that I know that is a Blueprint.

This is very useful when we have a lot of files in our project and we are looking for specific things to use.

Now that we have a custom GameMode, we can go back in the Project Settings -> Maps & Modes and from there, click on the drop down list for the Default GameMode and select the custom one we just created:

Img 11 - 80%

Now that we select a custom GameMode, we can see that the fields below are now editable:


Creating The Player Actor

While we can select a custom Default Pawn now,we didn’t create one.

To create a custom Pawn, inside the Blueprints folder Right Click -> Blueprint Class.

This time we are going to inherit from the Character:

Img 12
As you can see the Character is a type of Pawn that includes the ability to walk around.
 
Give the new Blueprint name BP_PlayerCharacter.
 
Now we can go inside the Maps & Modes and for the Default Pawn Class select our BP_PlayerCharacter:
 
Now instead of spawning the DefaultPawn the will spawn our BP_PlayerCharacter when we run the game:
 

When we press the Eject button after we run the game we don’t see the Sphere object that we saw in our previous testings.

That is because now our BP_PlayerCharacter is spawned in the game and we saw that inside the World Outliner tab where we selected our custom PlayerCharacter.

We could not see him inside the game however. And the reason for that is we didn’t attach any mesh components on our custom PlayerCharacter and we didn’t add any code to it that’s why we could not even move when we run the game.

The Blueprint Editor Window

To edit the BP_PlayerCharacter Blueprint, double click it to open it. If this is your first time opening a Blueprint the Blueprint Editor window will be floating so you will have to dock it, and you can do that wherever you wish:

It can also happen that you don’t see the editor window inside the Blueprint Editor, for that you can simply click on the Open Full Blueprint Editor button:

This is how the Blueprint Editor window looks like:

At the top left corner we have the Components tab where we can see the components that are attached on our Blueprint, and from there we can attach new components on our blueprint:

Img 15
Right below it, is the My Blueprint tab, inside we can see the functions and the variables we have declared for the current Blueprint:
 
Img 16

On the right side you see the Details tab which will display information about selected components and functions:

Img 17 - 75%
In the middle you will see three tabs. The first one is the Event Graph:
 

Inside the Event Graph is where we will place our Blueprint code e.g. the nodes that make the code.

Next we have the Viewport tab:

Inside the Viewport tab we will see the physical representation of our Blueprint e.g. how it will look like in the game.
 
Currently you see a Capsule or lines that are forming a Capsule.
 
This is because of the Capsule component that is attached by default on every Actor who inherits from the Character class.
 
The Capsule component is a solid body that will allow us to stand and move on the ground inside the level and it is not visible in the game e.g. the way we see the Capsule component in the Viewport tab, it is not visible in the game.
 
When we start working with 3D models inside the Viewport tab is where we will see those 3D models when we attach them on the Blueprint.
 
And the last tab is the Construction Script tab:
 
Inside the Construction Script tab we can add our initialization code which will be executed before any code inside the Event Graph is executed.
 
We will be spending the majority of our time inside the Event Graph and the Viewport tabs.
 

Making The PlayerCharacter Visible In The Game

Now that we know our way around the Blueprint Editor, let us add a simple mesh to our PlayerCharacter to make him visible.
 
Inside the Components tab, click on the Add Component button and from the search bar filter for Static Mesh a click on it to add it to the PlayerCharacter:
 
Img 21

Every time you make a change you want to apply to your current Blueprint, first click the Compile button and then the Save button in the Toolbar:

This is really important to do because this will apply the changes we made to the Blueprint.
 
Now click on the StaticMesh component that we added, and inside the Details tab under the Static Mesh settings, we can select which mesh to use by clicking on the drop down list:
 
Img 23 - 50%
From the drop down list you can select any mesh that you want or use the search bar to filter for meshes.
 
Let’s type sphere in the search bar and select it.
 
Make sure that you Compile and Save and if you take a look inside the Viewport tab this is what you will see:
 
As you can see the Sphere mesh is now visible inside the Viewport tab.
 
If we run the game now to test it, inside the Level Editor, this is what you will see in the level:
 
As you can see, the Static Mesh we attached to the PlayerCharacter is now visible inside our game after we added the Sphere mesh to it.
 
This was just for demonstration purposes to see how we can attach components on Blueprints and how can we make the PlayerCharacter visible.
 
Since our game is a first person view game, we can now delete the Static Mesh component inside the Blueprint Editor for the PlayerCharacter.
 
To delete the Static Mesh, select it and press the Delete button on your keyboard or Right Click -> Delete
 

After you deleted the Static Mesh component press the Compile and then Save buttons to apply those changes to the Blueprint.

Adding The Camera Component To The PlayerCharacter

Inside the Blueprint Editor for the PlayerCharacter in the Components tab click on the Add Component button and filter for the Camera component and attach it.

We already did this in the previous step when we attached the Static Mesh, the process is exactly the same except that instead of attaching a Static Mesh, we will attach a Camera component:

Img 25
Compile and Save the change and select the Camera component. Inside the Details tab change the values for the axis of the Location property:
 
Img 26 - 85%
The components we attach to Blueprints also have properties like Transform which has Location, Rotation and Scale values.
 
And we can change those values to reposition, rotate and resize the component.
 
One thing worth mentioning is the values we change for the Transform properties, they are in respect to the Blueprint Actor.
 
For example, if we attach a Static Mesh to our PlayerCharacter Blueprint and change the location values for the attached Static Mesh, these location values will change in respect to the PlayerCharacter location.
 
We can see that in action with our Camera component because now this where it is positioned:
 
Img 27 - 70%

You can play with the Location of the Camera component and you will see every time you change the values the Camera component will be positioned relative to the position of the PlayerCharacter Blueprint.

Setting Up The Movement Input

We only have the Camera component attached on the PlayerCharacter Blueprint, so if we run the game now everything will be the same.

We have our first person view, we are standing in one place and we can’t move. To fix this, we need to set up the input first.

The input set up is located in the Project Settings which is under Edit -> Project Settings.

Inside the Project Settings click on Input which is located under the Engine category on the left side:

Inside the Input tab you will see a sub-tab called Bindings. In that tab we can create Action Mappings and Axis Mappings.
 
And you can see the explanation what both are doing right below the Bindings tab.
 
Basically both Action and Axis Mappings allow us to bind keys to them and when we press those keys then the Action or Axis Mapping will be executed.
 
To create a new Action or Axis mapping you will press on the + button to the right of them:
 
As you can see from the example above, when you click on the + button a new mapping field will be created.
 
First you give it a name, and the name will be meaningful like Jump, MoveLeft, MoveUp, and so on, indicating what that mapping is intended for.
 
Then you map the key to it e.g. you select the key for your desired platform that when pressed, that mapping will be executed.
 
And there are multiple platforms that you can choose from, like keyboard for desktop, joystick, gamepad, ps4, xbox and so on:
 
This is going to be the set up for our input needs:
 
Img 29
The inputs Left, Right, Up, and Down refer to the arrows on the keyboard, so Left is actually the Left Arrow, Right is the Right Arrow and so on.

You will notice that some Axis Mappings have multiple keys that we can press to trigger them.
 
To create an extra input for the mapping, press the + button right next to it and from the new field select your desired input:
 

As you can see from the example above, you can add and remove extra inputs for every Mapping.

The same way you can also remove the Mapping by pressing the X button on the right side of the Mapping.

Unreal Engine Coordinate System

One thing that you also notices is that the Axis Mappings have a Scale value to the right of them, and those values are either 1 or -1 depending on the input:
 
Img 30

What does that mean?

Well the Scale is the multiplier to use for the mapping when accumulating the axis value.
 
In other words, since we are using the Axis Mappings for movement and rotation, depending on where we are moving and rotation e.g. up, down, left, right, and so on, we will use the appropriate Scale value.
 
To understand this better we need to take a look at Unreal Engines coordinate system which looks like this:
 
Img 31 - 80%

As in any 3D space we have the X, Y, and Z coordinates.

From the image you can see that the X coordinate is the left – right, Y is the Up – Down, and Z is the Forward – Backward coordinate.

Another thing that you will notice on every coordinate is that we have a positive and a negative side.

On the X axis left side is the negative side and right side is the positive side. On Y axis up is positive, down is negative and on the Z axis forward is positive and backward is negative. 

This is really important to know because if we want to move an Actor in a certain direction we need to know if that direction is positive or negative.

This is where the Scale value comes in. We use the Scale value and multiply the movement with it depending on the direction where the Actor is moving.

This is why for some directions the Scale value is 1 and for others the Scale value is -1.

To be more specific, for A and Left the Scale value is -1 because when we press one of the two keys we will move to the left side.

For D and Right the Scale value is 1 because when we press one of the two keys we will go to the right side.

The same explanation goes for the keys under the MoveForward Axis Mapping, the Scale value for W and Up is 1 because when we press one of the two keys we will move forward.

And the Scale has a -1 value for S and Down because when we press one of the two we will move backwards:


Where To Go From Here

In this tutorial you learned what is a Game Mode, how to create Blueprints, and how to set up the Input system.

In the next part of this tutorial series titled Moving The PlayerCharacter With Visual Code you will learn how write code inside the Blueprint editor and how to move Actors in the game.

Leave a Comment