0
0
Unityframework~10 mins

Blend trees in Unity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Blend trees
Start Animation State
Get Input Parameters
Evaluate Blend Tree
Calculate Blend Weights
Mix Animations Based on Weights
Output Final Animation Frame
Loop
Blend trees take input values, calculate weights for animations, mix them smoothly, and output the final animation frame.
Execution Sample
Unity
BlendTree blendTree = new BlendTree();
blendTree.AddMotion(walkAnimation, 0f);
blendTree.AddMotion(runAnimation, 1f);
float speed = 0.5f;
AnimationClip current = blendTree.Evaluate(speed);
This code creates a blend tree with walk and run animations and evaluates the blended animation at speed 0.5.
Execution Table
StepInput Parameter (speed)Blend Weights (walk, run)ActionOutput Animation
10.0(1.0, 0.0)Select walk animation fullywalkAnimation
20.5(0.5, 0.5)Blend walk and run equallyBlended walk/run animation
31.0(0.0, 1.0)Select run animation fullyrunAnimation
41.2(0.0, 1.0)Clamp to max run animationrunAnimation
5ExitN/AInput out of range or animation playedStop or loop animation
💡 Input parameter exceeds blend range or animation ends, stopping evaluation.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
speedundefined0.00.51.01.21.2
blendWeightsundefined(1.0, 0.0)(0.5, 0.5)(0.0, 1.0)(0.0, 1.0)(0.0, 1.0)
outputAnimationundefinedwalkAnimationBlended walk/run animationrunAnimationrunAnimationrunAnimation
Key Moments - 2 Insights
Why does the blend weight for run animation stay at 1.0 even when speed is 1.2?
Because the blend tree clamps input values to the max defined motion (1.0), so speeds above 1.0 use full run animation as shown in execution_table step 4.
How does the blend tree decide the weights for walk and run at speed 0.5?
At speed 0.5, the blend tree calculates weights proportionally between walk (0.0) and run (1.0), resulting in equal weights (0.5, 0.5) as in step 2.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what are the blend weights at step 2 when speed is 0.5?
A(1.0, 0.0)
B(0.5, 0.5)
C(0.0, 1.0)
D(0.25, 0.75)
💡 Hint
Check the 'Blend Weights' column at step 2 in the execution_table.
At which step does the blend tree use only the run animation without blending?
AStep 3
BStep 2
CStep 1
DStep 5
💡 Hint
Look for where blend weights are (0.0, 1.0) in the execution_table.
If the input speed was 0.25, how would the blend weights change compared to step 2?
AWeights would be (0.5, 0.5)
BWeights would be (0.25, 0.75)
CWeights would be (0.75, 0.25)
DWeights would be (1.0, 0.0)
💡 Hint
Weights are proportional to input between 0.0 and 1.0 as shown in variable_tracker for speed and blendWeights.
Concept Snapshot
Blend trees mix animations smoothly based on input parameters.
Define motions with parameter values.
Input controls blend weights between motions.
Weights sum to 1 for smooth transitions.
Clamp inputs outside defined range.
Output is the final blended animation frame.
Full Transcript
Blend trees in Unity take input values like speed to decide how much to mix different animations. The process starts by reading the input parameter, then calculating blend weights for each animation based on that input. For example, if speed is 0.5 between walk (0.0) and run (1.0), the blend weights are equal, mixing both animations evenly. If the input goes beyond the max defined value, the blend tree clamps it to the max animation. This way, the output animation smoothly changes as input changes, creating natural transitions. The execution table shows step-by-step how input affects weights and output animation. Variables like speed and blendWeights update each step, guiding the final animation frame output.