Skip to main content

๐ŸŒณ Lesson 1.3: Blend Trees

In Lesson 1.2 our character snapped between a separate Idle and Run state. Real locomotion doesn't snap โ€” it eases from a standstill into a walk into a full sprint. A blend tree does exactly that: instead of picking one clip, it mixes several based on a parameter, so speed changes look continuous and natural.

๐ŸŽฏ Learning Objectives

By the end of this lesson, you will be able to:

  • Explain what a blend tree is and why it beats hard state switches for locomotion
  • Create a blend tree state and choose its blend parameter
  • Add motions with thresholds and read the 1D blend graph
  • Drive the blend from code with a single SetFloat call
  • Recognise when to reach for a 2D (directional) blend tree instead

Estimated Time: 40 minutes  ยท  Prerequisite: Lesson 1.2 (States & Transitions)

In This Lesson

Why Blend, Not Switch?

Picture the Idle โ‡„ Run machine from Lesson 1.2. The moment Speed crossed 0.1, the character flipped from a still pose to a full run. Even with a short transition duration smoothing the cut, there's no walk in between โ€” no jog, no gentle acceleration. The character has two gears: parked and sprinting.

Humans (and robots like Timmy) have infinite gears. As you push a thumbstick further, the character should ease from standing to strolling to jogging to sprinting, matching the exact input. Wiring a separate state and transition for every speed band would be a nightmare of arrows. A blend tree collapses all of that into a single state.

๐Ÿ“– Definition

Blend tree: a special Animator state that plays several motions at once and cross-fades between them based on one or more parameters. At Speed = 0 you see pure Idle; at Speed = 6 pure Run; at Speed = 3 a real-time mix of Walk and the clips on either side of it.

What a Blend Tree Is

A blend tree lives inside a single state. From the outside โ€” on the main Animator canvas โ€” it looks like any other state box (often named Locomotion or Idle Walk Run Blend). Transitions still enter and leave it exactly as you learned last lesson. Double-click it, though, and you drop into the blend tree editor, a second graph showing the motions it mixes.

The key idea: one parameter drives a smooth mix. Instead of "if Speed > 0.1 go to Run," a blend tree says "at every value of Speed, here's the exact recipe of clips to blend." You give it the ingredients (clips) and the value each one is strongest at (its threshold), and Unity interpolates everything in between.

๐Ÿ’ก Blend trees vs. transitions. Transitions are for distinct actions โ€” idle, jump, attack, die. A blend tree is for a continuous spectrum of one action โ€” how fast you move, or which direction you strafe. Most controllers use both: a blend tree for locomotion, plain states around it for jumps and hits.

Creating a 1D Blend Tree

Let's replace the old Idle/Run pair with one blended locomotion state:

  1. In the Parameters panel, make sure you have a Float parameter named Speed (the same one from Lesson 1.2).
  2. Right-click the Animator canvas โ–ธ Create State โ–ธ From New Blend Tree. Name the state Locomotion and set it as the default state.
  3. Double-click Locomotion to enter the blend tree editor.
  4. In the Inspector, set Blend Type to 1D and the Parameter to Speed.
  5. Under Motion, click the + โ–ธ Add Motion Field three times and assign your Idle, Walk, and Run clips.
  6. Set each motion's Threshold โ€” the Speed value at which it plays at full strength. For example Idle = 0, Walk = 2, Run = 6.

That's it โ€” no transitions between the three motions. The blend tree handles the mixing internally; from the main canvas Locomotion behaves like one tidy state.

โœ… Pro Tip

Tick Automate Thresholds only if your clips already move at their real-world speeds (Unity reads the root motion speed to place them). Otherwise set thresholds by hand โ€” it gives you direct control over exactly when the walk becomes a run.

Reading the Blend Graph

Here is the 1D blend tree editor for our Locomotion state, drawn exactly as Unity lays it out. The bar at the top is the Speed parameter; the little red diamond is the current value, and the graph below shows how much each clip contributes as Speed changes.

The Unity 1D Blend Tree editor A recreation of Unity's blend tree Inspector and graph. At the top a Speed parameter slider shows a red marker near the walk range. Below, a blend graph plots three influence curves peaking at thresholds 0 (Idle), 2 (Walk) and 6 (Run). A motion list at the bottom shows three rows: Idle threshold 0, Walk threshold 2, Run threshold 6. Inspector โ€” Blend Tree Blend Type 1D Parameter Speed Speed 2.4 0 2 6 Speed (blend parameter) โ†’ Idle Walk Run mostly Walk + a little Run Motion Threshold โ‰ก Idle 0 โ‰ก Walk 2 โ‰ก Run 6
Figure 1: The 1D Blend Tree editor (faithfully recreated). Each clip's influence peaks at its threshold and fades toward its neighbours. At Speed 2.4 (red line) you get mostly Walk with a touch of Run โ€” a live blend, not a switch.

Notice there are no arrows inside the blend tree. The thresholds replace transitions entirely: wherever the red line falls, Unity reads how close it is to each threshold and mixes the clips in that proportion. Move it smoothly and the character accelerates smoothly.

Driving It from Code

Here's the payoff: driving a whole locomotion blend takes one line. You feed the same Speed float you used for transitions, and the blend tree does the rest. This uses the new Input System's InputAction to read a move vector (we cover the Input System fully in Module 3):

using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(Animator))]
public class LocomotionDriver : MonoBehaviour
{
    [SerializeField] InputActionReference moveAction; // a Vector2 "Move" action
    [SerializeField] float maxSpeed = 6f;             // matches the Run threshold

    Animator animator;
    static readonly int SpeedHash = Animator.StringToHash("Speed");

    void Awake() => animator = GetComponent<Animator>();

    void OnEnable()  => moveAction.action.Enable();
    void OnDisable() => moveAction.action.Disable();

    void Update()
    {
        Vector2 move = moveAction.action.ReadValue<Vector2>();
        float speed = move.magnitude * maxSpeed;   // 0 when still, up to maxSpeed

        // One call feeds the entire Idle/Walk/Run blend.
        animator.SetFloat(SpeedHash, speed, 0.1f, Time.deltaTime);
    }
}

Two touches worth copying: we cache the parameter name as a hash with Animator.StringToHash (the fragile-strings tip from Lesson 1.2), and we use the damped overload of SetFloat โ€” the extra 0.1f and Time.deltaTime arguments ease the value toward its target so a sudden stick flick doesn't snap the blend.

โš ๏ธ Match your thresholds to your speed range

If your top threshold is 6 but your code never sends Speed above 3, the character will never reach a full Run โ€” it caps out mid-blend. Keep the Run threshold and your maxSpeed in sync, and always send 0 when the stick is centred so Idle plays cleanly.

2D Blend Trees: Adding Direction

A 1D tree blends along a single axis โ€” great for "how fast." But what about "which way"? A top-down shooter or a strafing third-person character needs to blend forward, backward, and sideways motion at once. That's a 2D blend tree: two parameters (say MoveX and MoveY) place each clip at a point on a plane, and Unity blends by how close the input is to each point.

When you set Blend Type to a 2D mode, the graph becomes a square field instead of a line, and each motion gets a 2D Position instead of a single threshold:

  • 2D Simple Directional โ€” one clip per direction (forward, back, left, right). Best when motions point clearly outward.
  • 2D Freeform Directional โ€” directions plus different magnitudes (walk-forward and run-forward together).
  • 2D Freeform Cartesian โ€” arbitrary positions when the two parameters aren't really "directions" (e.g. Speed and Turn).

The workflow is identical to 1D โ€” add motions, position them, feed the parameters from code โ€” just with an X and a Y. For most character controllers a 1D Speed blend plus a couple of plain states is plenty; reach for 2D only when direction genuinely matters.

flowchart TB subgraph OneD["1D Blend Tree"] P1["Speed (float)"] --> M1["mixes Idle ยท Walk ยท Run
along one axis"] end subgraph TwoD["2D Blend Tree"] P2["MoveX + MoveY (two floats)"] --> M2["mixes directional clips
across a plane"] end

Figure 2: A 1D tree blends along one parameter; a 2D tree blends across two.

The Real Thing: Timmy's Blend

Remember the run render back in Lesson 1.2 โ€” the one where Timmy leaned naturally into his stride rather than snapping to a pose? That lean is a blend tree at work. Timmy's actual controller from the Starter Assets - ThirdPerson package doesn't have separate Idle and Run states at all. It has a single 1D blend tree state named Idle Walk Run Blend, driven by the same Speed float, mixing an idle, a walk, and a run exactly like Figure 1.

๐Ÿ”Ž Look for yourself: open Assets โ–ธ โ€ฆThirdPersonController โ–ธ Character โ–ธ Animations โ–ธ StarterAssetsThirdPerson.controller and double-click the Idle Walk Run Blend state. You'll see the 1D graph, the Speed parameter, and the three motions with their thresholds โ€” the production version of everything you just built.

Hands-on Challenge

๐Ÿ‹๏ธ Exercise 1: Build a 1D locomotion blend

Objective: Replace a hard Idle/Run switch with one smooth blend tree.

  1. In a controller with a Speed float, right-click โ–ธ Create State โ–ธ From New Blend Tree. Name it Locomotion and set it as default.
  2. Enter the tree, set Blend Type to 1D and Parameter to Speed.
  3. Add three motions โ€” Idle, Walk, Run โ€” with thresholds 0, 2, 6.
  4. Press Play. In the Animator window, drag the Speed value from 0 up to 6 and watch the character ease from standing through a walk into a run โ€” no visible snap.
๐Ÿ’ก Hint: it jumps straight to Run or never leaves Idle

Check your thresholds are in ascending order and spread across your real Speed range. If Walk and Run share a threshold, or the top threshold is far above the Speed you ever send, the blend won't spread out. Widen the thresholds to match the values your code (or the manual drag) actually produces.

โœ… Success check

Dragging Speed 0 โ†’ 6 produces a continuous change: pure Idle at 0, a clear Walk around 2, a full Run at 6, and smooth mixes in between โ€” all inside a single state with no transition arrows.

๐Ÿ‹๏ธ Exercise 2: Feed it from input

Attach the LocomotionDriver script and wire a Move action to its moveAction field (or, if you haven't reached Module 3 yet, temporarily drive Speed from the keyboard). Confirm that pushing the stick further makes Timmy accelerate through the blend, and that centring it returns him to Idle. Bonus: remove the damping arguments from SetFloat and feel how much snappier โ€” and less natural โ€” the blend becomes.

๐ŸŽฏ Quick Quiz

Question 1: What replaces transition arrows inside a 1D blend tree?

Question 2: You want a character to blend forward, back, and strafing motion at once. Which tool fits?

Question 3: From code, how many parameters do you set to drive the whole Idle/Walk/Run 1D blend?

Summary

๐ŸŽ‰ Key Takeaways

  • A blend tree lives inside one state and mixes clips instead of switching between them.
  • A 1D blend tree blends along a single parameter (e.g. Speed); each motion has a threshold where it peaks.
  • Thresholds replace transition arrows โ€” Unity cross-fades between neighbouring motions automatically.
  • Drive the whole blend with a single SetFloat; the damped overload smooths sudden input changes.
  • A 2D blend tree uses two parameters to blend directional motion across a plane.
  • Timmy's real controller uses an Idle Walk Run Blend 1D tree โ€” the production version of what you built.

๐Ÿš€ What's Next?

Your character now moves smoothly, but animation can do more than pose a mesh โ€” it can trigger events at exact frames (a footstep sound, a hit check) and even move the character itself. In Lesson 1.4: Animation Events & a Character Controller we tie the whole module together into a small playable demo.

๐ŸŒณ Smooth motion, one parameter

Idle, walk, run โ€” one float, one state, infinite gears in between. That's the difference between a prototype and a game that feels good to move.