top of page

Tutorial: Creating Playable Characters in UE4 | Part 2

(Part 2)

Contents

Contents

Introduction

Creating the Animation Blueprint

The Animation Blueprint Editor

Getting the Character

Adding Animations

Adding an Idle

Walking

Jumping

Connecting the Animations to the Character

Conclusion

Further Reference

Introduction

This tutorial is in two parts. The first part focused on importing the character and setting it up so that it can be used in game. The second part will now focus on adding animations to the character.

Creating the Animation Blueprint

The animation blueprint is the controller for all the animations used on the character. Through it we can control when an animation is played.

Navigate to the anim folder for the character. In this, create a new animation blueprint using the character’s skeleton. Call it aniCtrl_player (or if your character has a different name, substitute “player” for this. Keep it the same as what you named the character blueprint). Open it up to edit.

The Animation Blueprint Editor

If you're new to the animation blueprint, take a moment to look around. On the left will be a viewport where you can see your character and the currently playing animation (to start with, it will not be playing any animation yet). Below this will be where the animation variable defaults will be, and where you can change them to preview the animations. Most of the screen will be taken up by a graph with a “Final Animation Pose” node in it. Down the bottom of the screen is the asset browser (automatically shows the animation files available) and the My Blueprint tab which is the same as the one found in other blueprint editors. The section to the left of this is for the settings. If you would like more information on the animation blueprint editor you can find it in the Unreal Engine documentation.

Getting the Character

For the animations to work, the first step will be telling the blueprint what the player is and exposing any variables we need from this. For example, for the animation blueprint to know when to play the jump animation, we need to know when the jump action has been executed by the player.

Go to the event graph tab. From the execution pin on the “Event Blueprint Update Animation” node, search for “Cast to char_player” (if you named the character blueprint something else then it will be whatever you called it). Connect the “Try Get Pawn Owner” to the object input of the cast node as well. Drag a connection from the “as char_player” output and search for the “isJumping” boolean, select the get node. Drag another connection from the pawn owner node and search for get velocity. From this search for vector length. We now need to create two variables that will drive the animations. The first will be a boolean called “isJump” and the second will be a float called “speed”. Once created drag both of them into the graph as set nodes. Connect the output of the “isJumping” node (from the character) to the input of the “isJump” node. Connect the output of the vector length to the input of the “speed” node.

Adding Animations

We can now start adding animations. Switch back to the anim graph tab. Drag off a connection from the node and search for “state”. Add a new state machine node. Call this “defaultState”. This node will contain the animations we want the player to use. Double click the node to enter the graph.

Planning Ahead

Adding animation graphs can get quite complicated. You need to take into account all the possible actions the player can do in the game and then all the possible scenarios that can lead to that action. Our character for example will have three animations, idle, jump and walk. We need to plan out when each of these animations will play.

When the character is first spawned it will enter the idle animation. It stays in this forever until we do something else. From the idling position we will be able to walk and jump. From the walk we will be able to go back to idle or perform a jump. If we jump while walking, we will then be able to go back to the walk or back to the idle depending on whether or not we have stopped moving forward. To control each of these actions we have transition rules. It is a good idea to plan out and even draw up the graph before you start adding the animations.

Adding an Idle

In the section that has the “Asset Browser” and “My Blueprint” tabs, switch to the asset browser. Drag in your idle animation and connect the entry node to this. Save and compile. You will now notice that the viewport will show the character idling.

Walking

Now drag in the walk animation. Make a connection FROM the idle animation TO the walk animation. You will see that the line has an arrow indicating the direction of the path. It also has an icon next to it. Double click this. This opens up the transition rule graph. In here are the rules for when the animation controller will transition from idle to walk. In our case, we only want to start walking when the character's speed is greater than 0. Drag in the speed variable (as a get node) and off this search for “>” or “greater than”. Choose the “Float>Float” node. In the second slot of this node, set the value to 0.1. Connect the output of this to the result node.

Close this tab and go back to the state graph. make a new connection FROM the walk TO the idle. Open up the transition rule. This time, we want the transition to be made when the player stops moving, i.e. the speed is less than or equal to 0. So, get the speed variable and search for “<”. Place the “Float<=Float” node. Connect it to eh result node. Close the tab then save and compile the blueprint. You should now be able to increase and decrease the speed in the “Anim Preview Editor” tab and see the character play the idle and walk animations.

Jumping

Let's start with the jump from idle first. Make a connection FROM idle TO jump. Open up the transition. All we need to do is check that the “isJump” variable is true in order to play the animation. Get the “isJump” variable and connect it to the result node.

Close the tab and make a connection FROM the jump TO the idle. Open it up.In order to go back to the idel state, we want to wait until the jump animation hsa finished and then go back. For this we need to search for “time remaining” and select the “time remaining for <anim name>”. Connect that to a “Float<Float” node and set the second value to 0.1. Connect this to the result node.

Make a transition FROM walk TO jump and set the transition up the same as the one from idle to jump. This is the only transition we will have. Once the jump is finished it will go back to the idle but because we are still moving it will then transition to the walk. This happens fast enough to not be a problem.

Connecting the Animations to the Character

There is now just one final step to getting the animations to play. Open up the character blueprint. In the components list, select the mesh. Over in the details, select the “Anim Blueprint Generated Class” to be the animation blueprint we just created.

Once this is done you can save and compile and then test out the character.

Conclusion

This is a simple way to setup a character in UE4. A full character would have many more animations, however this is a good starting point for getting a basic character in-engine and running around.

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