Animation State Machine: UE5 and Unity Locomotion Setup Guide

What an Animation State Machine Does

The animation state machine is the system that decides which animation plays at any given moment — and how to get from one animation to the next. Without a state machine, you have a collection of individual clips. With a well-built animation system, you have a character that responds smoothly to every movement condition: standing, walking, running, jumping, landing, and transitioning between combat and locomotion states without visible cuts or pops. This guide covers how to build one in both Unreal Engine 5 and Unity.

An animation state machine by default manages three things:

  • States — each state plays one animation or blend space (idle, walk/run, jump, fall, combat idle, etc.)
  • Transitions — conditions that trigger a move from one state to another (speed exceeds threshold, jump input received, character landed)
  • Blend times — how long the crossfade between two states takes, which determines how snappy or smooth transitions feel

Building a State Machine in Unreal Engine 5

  1. Open the Animation Blueprint. In the AnimGraph, right-click and select Add New State Machine. Name it (e.g., Locomotion).
  2. Double-click the State Machine to enter it. Right-click to add states. Each state contains an animation sequence, blend space, or sub-state machine.
  3. Create an Idle state. Inside, drag your idle animation sequence to the Output Pose.
  4. Create a Walk/Run state. Inside, drag a Blend Space 1D or 2D. Wire Speed and Direction from the Event Graph variables.
  5. Draw transition arrows between states. Click each transition arrow to set the condition: Speed > 10 to move from Idle to MoveLoop; Speed < 10 to return.
  6. Set blend times. Each transition has a default blend time (0.2 seconds is a common starting point). Shorter times feel snappier; longer times feel smoother but can look floaty.
  7. Add Jump, Fall, and Land states. Transition to Jump on a boolean (IsJumping), from Jump to Fall when the character begins descending, and from Fall to Land on grounded detection. Land transitions back to Idle or MoveLoop based on speed.

Building a State Machine in Unity

  1. Right-click in the Project panel, Create → Animator Controller.
  2. In the Animator window, add parameters: Float (Speed), Bool (IsGrounded, IsJumping), and Trigger (Land).
  3. Right-click in the Animator window → Create State. Each state references an animation clip or a Blend Tree.
  4. Right-click → Create State → From New Blend Tree for locomotion. Use 1D or 2D blend type. Add Idle at Speed 0, Walk at 0.5, Run at 1.0.
  5. Right-click a state → Make Transition → drag to the target state. Set conditions on each transition arrow.
  6. Uncheck Has Exit Time on transitions that should respond immediately to input. Exit Time-based transitions wait for the clip to finish, which creates input lag.
  7. Drive from code: animator.SetFloat("Speed", velocity.magnitude) and animator.SetBool("IsGrounded", isGrounded) each Update.

State Machine vs. Blend Space: When to Use Each

Use a Blend Space when… Use a State Machine transition when…
Movement is continuous and speed-driven (walk → run) Movement changes are discrete (grounded → airborne)
You need smooth direction blending A specific clip must play to completion before transitioning
Multiple animations should blend simultaneously States are mutually exclusive (cannot be walking and jumping at the same time)

In practice, most production locomotion systems use both: a Blend Space inside a Walk/Run state for smooth speed and direction blending, and a State Machine around that Blend Space for discrete state changes like jumping and landing. See the animation blend tree guide for full blend space setup detail.

Common Architecture Mistakes

The most expensive mistake in animation state machine design is building transitions before the states are stable. Developers who jump straight from asset import to transition logic end up with a brittle graph where fixing one transition breaks two others. Verify each state plays correctly in isolation first — the idle loops cleanly, the walk cycle has no foot slide, the run clips are at the right speed — before connecting any transitions.

Transition blend times are a systematic source of animation quality issues. The default blend time in both Unreal Engine and Unity is 0.2 seconds, which is appropriate for locomotion transitions but incorrect for many combat and reaction states. A hit reaction should transition in with a very short blend (0.05–0.1 seconds) to feel responsive. Reviewing transition blend times systematically — one pass per transition type — produces a measurable improvement in animation feel without requiring any new clips.

Hierarchical State Machines for Larger Projects

Hierarchical state machines (sub-state machines in Unity, nested state machines in UE5) are the correct tool when state count grows beyond 15–20 states. The standard pattern creates sub-machines for each behavioral domain: a Locomotion sub-machine contains all movement states, a Combat sub-machine contains attack and defense states, and a Reaction sub-machine contains hit, stagger, and death states. The top-level machine manages which domain is active and transitions between domains. Adding a new combat move does not risk breaking locomotion transitions, and vice versa.

Combat State Machine Design

Combat animation state machines differ from locomotion state machines because they involve committed actions, interrupt windows, hit reactions, and multi-phase attack sequences. Every combat state falls into one of two categories: committed (the animation plays to completion regardless of input) or interruptible (input can cancel the animation at defined windows). Define interrupt windows explicitly — "this state can be exited from frames 18–35 only" — rather than implicitly via transition priorities.

For hit reactions, two common approaches work well: additive hit reactions that play as an additive layer on top of the current state (the character flinches without stopping their run cycle), or full-body override with return for large impacts (stagger, knockdown) that override the current state entirely and transition back based on gameplay context after recovery.

Combo attacks work cleanest as a single "Attack" state with an attack index variable that increments on each input, driving an animation selector within that state — rather than separate Attack1, Attack2, Attack3 states with redundant transition rules between them.

Getting the Right Animation Clips for Your State Machine

A well-structured animation state machine turns a collection of animation clips into a responsive character system. MoCap Online's motion capture animation packs are organized to populate this structure directly: complete locomotion sets with idle, walk cycle, run cycle, and transitions, all matched to the same skeleton and delivered in engine-native formats for Unreal Engine, Unity, Blender, iClone, and FBX. Download a free sample pack to get started.