top of page

Tutorial: Creating Playable Characters in UE4 | Part 1


(Part 1)

Contents

Contents

Introduction

Importing the Character

What You Need

Organisation

Inputs

Actions

Axis

Creating the Character Blueprint

Setting up the Mesh

Setting up the Graph

Looking

Movment

Jumping

Game Modes and Levels

Testing

Conclusion

Further Reference

Introduction

This is the first part in a two part series on creating a basic playable character in Unreal Engine 4. The second part of the tutorial will cover the animation blueprint and how to set up the animations.

Importing the Character

What You Need

You will need:

1x Skinned mesh FBX file

1x Idle animation

1x Walk/Run animation

1x Jump animation

The character’s FBX should have the skinned mesh and skeleton. The animation files don’t need to contain the mesh, just the animated skeleton. Importing the character mesh will create a skeletal mesh asset, physics asset and the skeleton asset. Import the character first so that these assets get created. You can then select the skeleton when you import the animation files.

Organisation

To keep things organised, we will create some folders first. Create a new folder in the content browser called Characters. Inside this create another folder called charPlayer (or, substitute the word “player” for your characters name). Inside this create a folder called anims. The charPlayer folder will be where the skeletal mesh, physics asset and skeleton are kept. The anims folder is where all the animation files will be kept. Each new character would have it’s own folder with this layout.

Example:

Characters

charPlayer

anims

anim_player_idle

anim_player_run

… (other animation files)

m_player (the skeletal mesh)

pa_player (the physics asset)

skl_player (the skeleton)

There will also be a folder in the content directory called blueprints, then, inside this a folder charPlayer folder. This will be where the character blueprint (and any other scripts needed by the player) are kept.

Inputs

To create a playable character we will need to setup inputs to use in the blueprint that will control the player's movement and animations, as well as any extra attributes the character might have.

First step will be to open the project settings (Edit > Project Settings) and go to the input tab. This is where you setup the controls for the game. The first section, Bindings, is for the general action (e.g pick up key) and axis (e.g. movement) controls. For this tutorial we will setup controls to allow the character to walk around and jump using a keyboard and mouse. This will contain one action mapping and four axis mappings.

Actions

Add a new action mapping by clicking the plus icon. Call this jump and select the space bar as the key binding.

Axis

Next, add a new axis mapping called moveFB. This will be for the forward and back controls, which will be mapped to W and S. For the first key binding select the W key and keep the scale set to 1. Click the plus icon next to the text field. This will add another key binding to the same axis. This time, select the S key and set the scale to -1.

Now we will add another axis mapping for left and right movement, or “strafing”. Call this axis moveLR and add to key bindings to it. The first will be for the A key, with the scale set to -1. The second key will be set to D and have a scale of 1. This will allow the player to move left and right.

The third and fourth axis mappings will be for the mouse to move left and right, as well as up and down. The first of these will be called lookLR and will have Mouse X set as the binding. The second axis will be called lookUD and will have the Mouse Y axis binding. Leave both scales as 1. You could invert (set to -1) the scale of the lookUD input but this is also something that could be done elsewhere in a blueprint to allow the player to control this. (However this is beyond the scope of this tutorial).

Creating the Character Blueprint

Setting up the Mesh

Now that we have the controls set up, it’s time to create the character blueprint. In the charPlayer folder under prefabs, create a new blueprint and select the character class. Call it char_player. Open it up so that we can edit it. In the components list, there will be a capsule component with two children, an arrow and a mesh component. Select the mesh component and over in the details tab, select your character mesh. Move and position this so that the base of the character is at the base of the capsule component. If it is too big or too small, select the capsule component and edit the half height and radius to better suit your character. You may also need to reposition the character after that.

Once you have that done, select the capsule component in the component list and add a new component called a spring arm. Name this sArm_camera. Also add a camera component and call this camPlayer. Drag the camera under the spring arm to make it a child. Make sure the camera has no transform values. Move the spring arm up to about the neck hight. See below.

There are also some settings on the spring arm you will want to change. The settings of these are up to you, and will depend on how you want your character controls to be like so take the time to experiment with different settings. There is one setting however we will change. Set the “Use Pawn Control Rotation” option to true. This will allow the camera to be tilted up and down. Moving the mouse side to side will turn the character, while still keeping the camera behind the player.

Setting up the Graph

Now switch over to the graph tab.

Looking

This is the simplest part of the blueprint. The mouse will be used to control the camera and the direction the character is pointing.

First up, right click on the graph and search for “lookLR” and select the option from the “Axis Events” section. This will bring in the axis input we created earlier. Drag a connection off from the execution (white) pin and search for “add controller Yaw”. Also connect the axis value from the input node to the “val” input pin on the Yaw node.

Now search for “lookUD” and select the one from the “Axis Events” section. Again drag a connection off from the execution pin and search for “add controller Pitch”. Connect them up.

Movment

Now we will make the character move forward, back, left and right. Search for the “moveFB” and get the axis event one. Also bring in the “moveLR” node. Create the following node network. This gets which key (from W, A, S and D) is being pressed and uses this to control the movement of the character.

Jumping

Start off by searching for the “jump” input node (from the action events section). From the “Pressed” pin search for “jump” and get the node form the “Pawn > Character” section. Hold down alt and drag in the “Character Movement” component from the components list. From this search for “set ZVelocity”. We could just type in a number but let’s make this a variable to allow for customisation later on. Right click the velocity input pin and select “promote to variable”. Call this new float variable jumpVelocity Set it to public and the default value to 400. Add another variable (by clicking the plus icon in the variable list) and call this isJumping. Change it to be a boolean variable. Alt drag this into the graph and link it up to the output of the “set jump Zvelocity” node. Also set the input to true. Duplicate the node and hook it up to the “Released” output of the action node. Make sure to set it to false. You should have a network that looks something like the below graph. Don’t forget to save and compile the blueprint.

Game Modes and Levels

Game modes can be thought of as a list of rules for the game. They contain what players to use and how many can be in the game at the one time. (For a more detailed description check out the UE4 documentation). For this tutorial, we will set up a new game mode that uses our character as the default player class.

In the content browser, create a new folder called levels. Inside this create a folder called gameModes. This will be where we keep our different game modes. Create a new blueprint and select the game mode option from the list. Call this gm_default. Open it up to edit the settings. The only setting we will change at the moment will be the “Default Pawn Class” under Classes. This is the default player to use when starting a game. From the drop down list, select the character we just made. Save and then close the blueprint.

Open up the project settings again and this time, take a look at the “Maps & Modes” section. Under the “Default Modes” tab, select our game mode we just created.

Setting the game mode here will set the project default for creating new levels. It is, however, possible to override this on a per level basis. When you have a level open, open up the world settings. There will be a game mode tab. This will say none by default, however you can select any game mode you want and the level will use that instead of the global default.

Testing

You should now be able to test your character. Keep in mind though that there are no animations. The movement however should work. It is a good point to test the camera position at this stage. Don’t forget you can invert the Y axis (lookUD) of the camera by changing the scale in the project settings to -1.

Conclusion

This concludes the first part of the tutorial. The second part will continue on by going through the steps on how to add animations to the character.

Further Reference

The Unreal Engine documentation is a great place to learn how to use the engine. There are also a number of tutorial which go through various aspects of creating assets. Below are some of the resources I used to first learn about setting up characters in UE4.

Setting Up Character Movement in Blueprints

Unreal Engine 4 Documentation | Game Modes

Unreal Engine 4 Documentation | Animation Blueprints

Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
    bottom of page