State Machines

State Machines allow Skeletal Animations to be broken up into various states, with full control over how blends occur from one state to another.

Choose your operating system:

Windows

macOS

Linux

Overview

Animation State Machines allow you to think of your Animation Blueprint in a more modular sense than you would without it. Users define a series of various states in which the character or Skeletal Mesh could possibly exist. Next, they define the circumstances in which the character or Skeletal Mesh may enter and exit each state, similar to a flow chart.

For instance, you may have a flow chart that defines the process of your character's animation that may look something like this:

AnimationFlowChart.png

If you were to set up a State Machine for the above flow, it might end up looking something like this:

StateMachine.png

Anatomy of a State Machine

State Machines are comprised primarily of a network of states and the rules that define transitions into and out of them. Each state, along with each rule set, is its own condensed Blueprint network. This makes it very easy to handle complex animation blending without having to use an overly complicated AnimGraph.

States

Conceptually, it is best to think of a state as an organized portion of an AnimGraph that we know the character or Skeletal Mesh will be blending into and out of on a regular basis. You can then transition into and out of this part of the graph. For instance, you may have an Idle state for your character's animation, and that state may just contain a single animation.

Here is such an Idle state seen from the State Machine.

State.png

Double-clicking on that state opens a graph where you define what will be the Final Animation Pose

IdleStateInside.png

Once the character started moving however, they could transition into a Movement state - which could define moving laterally across a surface, like walking or running.

MoveState.png

Within, this state may contain a BlendSpace that is being defined by the character's speed and direction of movement.

MovementInside.png

States have no pins in and of themselves, because they are intended to have a more freeform layout.

By dragging a wire from its outer border, you can connect states or create new states (similar to Blueprint).

DragWire.png

Transition Rules

Once you have your states defined, you need to be able to control how your Skeletal Mesh is going to transition from one state to another which is where Transition Rules come into play. Transition Rules are created automatically along the wires that connect states.

TransitionRule.png

Transition Rules can perform any number of checks and tests against variable values, all with the purpose of outputting a True/False value. This Boolean output determines whether the animation can move through the transition or not.

TransitionRuleInside.png

Above, we are testing the value of a character's Speed. Once it reaches a value greater than 10, we enable the transition. In this case, the character is allowed to move from an Idle state to a Movement state. We can then use a completely separate rule to transition back to Idle.

For example, here we have a transition rule moving back from Movement to Idle.

TransitionRuleReturn.png

Inside, we check to see if the same value we used to transition into the Movement state is no longer true.

TransitionRuleReturnInside.png

Conduits

Conduits serve as a more advanced and sharable transition resource. Where a Transition Rule is going to be a simple 1-to-1 relationship form one state to another, a Conduit can have 1-to-many, many-to-1, or many-to-many. Conduits appear on the graph and look similar to a State but have a different icon preceding the Conduit's name (below).

ConduitNode.png

An example use case for a Conduit could be a situation where you have multiple animations that could play when a character is killed.

You could start with a simple Transition Rule that says when the health of that character is less than or equal to 0, then go to a Death state. However, if instead of a State, the transition went into a Conduit, you could perform a series of checks to see how the player was killed (shot, stabbed, explosion, hit by a car, anvil on the head, etc.) and branch from there into various independent death States.

A simplified version of that graph may look something like below:

ConduitGraph.png

Inside, a Conduit graph looks just like a Transition Rule:

ConduitInside.png

The actual transition rules that exit the Conduit can then determine the type of death and allow blending to the appropriate state.

Mouse-Over Previewing

One of the features of a State Machine is its ability to provide previews on mouse-over for the State Machine itself, as well as for its component nodes. For example, if you hover your mouse over a State Machine, a preview window will pop up giving you a high-level view of the State Machine. This is similar to a collapsed Blueprint network.

StateMachineHoverPreview.png

These previews also extend to the various States and Transition Rules within a State Machine. Hovering over them will show you a preview of what is inside.

IdleStatePreview.png

In the case of Transition Rules, you will see not only a preview of the nodes, but also a breakdown of the rule in words.

TransitionRulePreview.png

Creating State Machines

Before actually creating your State Machine, it is a good idea to take a little time and plan out exactly which states you will need, as well as the circumstances that will drive transitions between states. This will give you a solid plan of attack for not only the State Machine but also the variables you will need to drive it and which animations will be a part of each state.

You can create a New State Machine inside the AnimGraph of an Animation Blueprint Editor:

  1. Right-click within the AnimGraph of your Animation Blueprint and choose State Machines > New State Machine from the context menu.

    CreateNewStateMachine.png

    Generally, it is a good idea to name your State Machine immediately after creation.

  2. Right-click the new State Machine in the My Blueprint window and enter a new name in the name field.

    RenameStateMachine.png

    In this case, the State Machine has been named "Locomotion."

    LocomotionSMNode.png

  3. You can open the State Machine to define its States and Transitions by Double-clicking it.

    StateMachineEntryPoint.png

    This will open a new graph tab with nothing but an Entry point, which essentially kicks off the animation.

Creating States and Conduits

Creating a new State is similar to creating new nodes within a Blueprint.

  1. You can Right-click and create one from the context menu.

    AddState_CM.png

    You can also drag a wire into an empty portion of the graph and release the mouse, which will also expose the context menu.

    AddStateDragWire.png

  2. You can rename your States by Right-clicking the node in the graph.

    StateDefault.png

    Above our State has been created and renamed to Idle below.

    StateRenamed.png

  3. Conduits are created in a similar manner, by either Right-clicking in the graph or dragging a new wire into an empty space on the graph.

    CreateConduit.png

Creating Transition Rules

Transition Rules are created automatically along the wires that connect States and Conduits. Graphically, Transition Rules appear as a small circular directional icon, like so:

NewTransitionRule.png

This means that when you create a new State or Conduit by dragging a wire into an empty space on the graph, a Transition Rule will automatically be created for that wire. Additionally, you can drag a wire back to the original node to create a second Transition Rule for transitioning back to that node.

CreateTransition.png

You can Double-click on a Transition Rule to open a new graph that will allow you to define the success or fail conditions for the transition.

TranstionRule.png

Above if the Boolean IsSecondaryAttacking? is True, then the transition into the new state can occur.

Editing State Machines

Although a State Machine serves as a convenient way to break down the flow of animation transitions in a Skeletal Mesh, the most important aspect of them is what actually happens within each node of a State Machine. With this in mind, it is important to remember the primary purposes of each of a State Machine's node types:

Node

Purpose

State

Output a pose or animation result.

Transition Rule

Govern whether animation will flow from one state into another. Uses a Boolean value to determine if the transition will take place.

Conduit

Also governs the flow of animation, but with the ability to share the transition cause among many different states. Uses a Boolean value to determine if the transition will take place.

Keeping this in mind will make it much easier to determine what types of nodes to place into each part of the State Machine.

Editing States

A State's job is to produce a final animation or pose. This can be a single AnimSequence, a BlendSpace, or any type of network so long as it produces a final animation or pose.

PlayAnimSequence.png

Above a single AnimSequence results in the Final Animation Pose.

PlayBlendSpace.png

Above a Blendspace is used to blend between different poses based on the value Speed.

PlayBlendAnimation.png

Above a different AnimSequence is selected based on the value of the Boolean Is In Air?

Adding Animation Elements

To add an AnimSequence or BlendSpace into a State's graph, you can drag-and-drop it from the Asset Browser in the Animation Blueprint Editor:

DragDropAnimSeqState.png

Or use the Right-click context menu and select an animation:

ContextMenuAnimSeqState.png

Automatic State Creation

To automatically create a State in a State Machine, drag an AnimSequence or Blendspace asset into the graph.

AutoStateCreationDrag.png

Once dragged in, the State is automatically created and named after the asset.

AutoStateCreation.png

Inside, you can see that the animation asset has been connected to the Final Animation Pose result automatically.

AutoStateCreationInside.png

Additional Resources

Here you can find additional resources about State Machine features in Unreal Engine.

This page was written for a previous version of Unreal Engine and has not been updated for the current Unreal Engine 5.0 release.