In this lesson, you will learn how to play two different animations simultaneously on a single character by using Animation Layers and Avatar Masks.
The Concept of Layers
In the Animator Controller, you aren't limited to a single state machine. By adding new layers, you can run multiple animations concurrently. For example, your character might be in a "Run" state on the Base Layer while simultaneously performing a "Wave" or "Reload" animation on a second layer.
By default, a new layer will override everything below it. To blend them intelligently, we use Avatar Masks.
Using Avatar Masks
An Avatar Mask acts as a filter, telling Unity which bones of your character model should be affected by that specific layer. If you want a "Reload" animation to only affect the upper body while your character continues to run, you create an Avatar Mask, select the "Humanoid" tab, and toggle off the legs and lower spine.
- Create the Mask: Right-click in your Project window:
Create > Avatar Mask. - Configure: Click your mask and choose "Humanoid." Click the body parts in the diagram to enable (green) or disable (red) the bones for that layer.
- Apply to Layer: In your Animator Controller, click the Gear icon on your new layer. Drag your created mask into the Mask slot.
- Set Blending: Ensure the Blending mode is set to "Override" (to replace base animation) or "Additive" (to layer movement on top), and set the Weight to 1 to fully enable the layer.
Practical Implementation
When triggering the animation via code, you still use your standard Animator references. Since the mask isolates the bones, the "Reload" state you trigger on the top layer won't interfere with the "Run" state on the base layer:
// Triggering the animation on the layer
animator.SetTrigger("Reload");
Because the Avatar Mask hides the lower body bones from this layer, the legs will continue to follow the base layer's "Run" animation, while the upper body switches to the "Reload" motion.
Key Takeaway: Animation Layers combined with Avatar Masks allow you to isolate animations to specific body parts, enabling complex, simultaneous character movements without creating unique animations for every possible combination.