Unreal Engine 4 Animation Tutorial
- Getting Started
- What is a Skeleton?
- Importing a Skeletal Mesh
- Using a Skeletal Mesh
- Importing Animations
- Creating an Animation Blueprint
- The Animation Blueprint Editor
- What is a State Machine?
- Creating a State Machine
- Linking an Animation to a State
- Using an Animation Blueprint
- Creating the Jumping and Falling States
- Transition Rules
- Checking if the Player is Jumping or Falling
- Defining the Transition Rules
- What is a Blend Space?
- Creating a Blend Space
- Adding Animations to a Blend Space
- Using Blend Spaces
- Getting the Player’s Speed
- Using the Death Animation
- Checking if the Player is Dead
- Using the Blend Poses by Bool Node
- Where to Go From Here?
You will rarely see a modern game without animation. This is because animation is key in conveying motion. Without animation, a character would just look like they’re sliding instead of running.
Luckily, Unreal makes it easy to get your characters animated in no time!
In this tutorial, you will learn how to:
- Import a mesh with a skeleton
- Import animations
- Create an Animation Blueprint to transition to different animations
- Blend between animations
Please note, you will be using Blueprints in this tutorial. If you need a refresher, check out our Blueprints tutorial.
- Part 1: Getting Started
- Part 2: Blueprints
- Part 3: Materials
- Part 4: UI
- Part 5: How To Create a Simple Game
- Part 6: Animation (you are here!)
- Part 7: Audio
- Part 8: Particle Systems
- Part 9: Artificial Intelligence
- Part 10: How to Create a Simple FPS
Download the starter project and unzip it. In the root directory, you will see a folder named Animation Assets. This folder contains the character and animations that you will be importing.
Open the project by navigating to the project folder and opening SkywardMuffin.uproject.
Press Play to start the game. The goal of the game is to touch as many clouds as possible without falling. Click the left-mouse button to jump up to the first cloud.
Instead of a plain red circle, let’s control this cute little muffin instead:
This muffin contains a skeleton which allows you to animate it.
What is a Skeleton?
In 3D applications, a skeleton is a set of interconnected points called joints. In the image below, each sphere is a joint.
By manipulating these joints, you can create different poses for your character.
When you go from one pose to another, you are creating an animation.
If you create more poses between the previous poses, you can get something like this:
In Unreal, any mesh with a skeleton is a Skeletal Mesh. Let’s begin by importing the Skeletal Mesh for the muffin.
Importing a Skeletal Mesh
Go to the Content Browser and navigate to Characters\Muffin. Click Import and then go to SkywardMuffinStarter\Animation Assets. Select SK_Muffin.fbx and then click Open.
In the import window, go to the Mesh section and uncheck the Create Physics Asset option. The Physics Asset helps create a ragdoll effect. Since this tutorial does not cover that, you do not need one.
The project already includes the muffin material and texture so you don’t need to import them. Uncheck the Import Materials and Import Textures options.
Leave everything else at their default settings and then click Import. This will create the following assets:
- SK_Muffin: The Skeletal Mesh asset. This is basically just a mesh with a link to a Skeleton asset.
SK_Muffin_Skeleton: The Skeleton asset. This holds a list of joints and other information such as their hierarchy.
Now that you have the muffin imported, it’s time to use it.
Using a Skeletal Mesh
Before you use your new Skeletal Mesh, you should give it a material so it’s not just a grey blob. Double-click on SK_Muffin to open it.
Go to the Asset Details panel and locate the Material Slots section. Assign the M_Muffin material and then close SK_Muffin.
Now, let’s use SK_Muffin as the player character. Go back to the Content Browser and double-click on BP_Muffin to open it.
Go to the Components panel and select the Mesh (Inherited) component. Navigate to the Details panel and locate the Mesh section. Set the Skeletal Mesh property to SK_Muffin.
Click Compile and then go back to the main editor. Press Play to play the game as a muffin!
The game is already looking a lot better! Your next step is to import some animations that will add life to the muffin.
Go to the Content Browser and click Import. Make sure you are in SkywardMuffinStarter\Animation Assets. Select the following files:
Once you have done that, click Open.
In the import window, go to the Mesh section and uncheck the Import Mesh option. This will make sure the Skeletal Mesh is not imported again.
Next, make sure the Skeleton property is set to SK_Muffin_Skeleton. This specifies which skeleton the animation will use.
Finally, click Import All. This will import all the animations with the settings you just specified.
Now that you have all your animations, you need a way to play them. You can use an Animation Blueprint to do this.
Creating an Animation Blueprint
An Animation Blueprint is like a regular Blueprint. However, it also features a graph dedicated to animation tasks.
To create one, go to the Content Browser and click the Add New button. Select Animation\Animation Blueprint.
In the pop-up window, locate the Target Skeleton property and select SK_Muffin_Skeleton. Next, click the OK button to create the Animation Blueprint.
Rename the asset to ABP_Muffin. Afterwards, double-click on it to open it in the Animation Blueprint editor.
The Animation Blueprint Editor
The Animation Blueprint editor is like the Blueprint editor but with four extra panels:
- Anim Graph: This graph is dedicated to animation. This is where you will play your animations.
- Preview Scene Settings: This panel allows you to tweak the preview scene in the Viewport
- Anim Preview Editor: Variables you create will also show up here. Use this panel to preview the effect your variables have on the final animation.
- Asset Browser: This panel contains a list of animations the current skeleton can use
To define when each animation should play, you can use a State Machine.
What is a State Machine?
A State Machine is a set of states and rules. For the purposes of this tutorial, you can think of a state as an animation.
State Machines can only be in one state at a time. To transition to a different state, certain conditions—defined by rules—must be met.
Below is an example of a simple State Machine. It shows the states of a jump and the rules for transitioning to each state.
States can also have a two-way relationship. In the example below, the Jump and Fall states can transition to each other.
Without this two-way relationship, a character wouldn’t be able to perform a double jump. This is because the character would only be able to enter the Jump state from the Idle state.
That’s enough about State Machines. Let’s go ahead and create a new State Machine.