Course contentsShow
← Unity Game Development
Lesson 384 of 8286. Animation and CinemachineFree lesson

Controlling Animation Layers for Partial Body Overrides

Utilize animation layers with weight masking to play upper-body actions simultaneously while the lower body continues walking.

In this lesson, you will learn how to use Animation Layers and Avatar Masks to play specific animations, such as a wave or a reload, on the upper body while keeping your character’s lower body locked into a walk or run cycle.

Why Use Layered Overrides?

In a standard Animator controller, the base layer handles your character's primary locomotion (walking, running, idling). If you simply play a "Wave" animation, the character would stop walking, play the wave, and then resume. To play two animations at once, we use Animation Layers. By assigning an Avatar Mask to a new layer, we instruct Unity to ignore the legs, hips, and spine in that layer, allowing those bones to continue following the "Base" layer's movement.

Setting Up the Mask

  1. Create the Mask: In your Project window, right-click and select Create > Avatar Mask.
  2. Configure the Mask: Select the mask and look at the Inspector. Under the "Humanoid" tab, you will see a visual representation of a body. Click the segments representing the legs and hips to deselect them (turn them red); keep the torso, arms, and head green.
  3. Apply to Animator: Open the Animator Window and click the Layers tab. Click the + button to create a new layer (e.g., "UpperBody"). Click the gear icon to open settings and assign your new Avatar Mask to the Mask slot.
  4. Sync and Blend: Set the Weight of this layer to 1. Ensure the Blending mode is set to Override, which tells Unity that this layer should replace the Base layer’s animation data for the masked-out body parts.

Scripting the Override

You don't need complex code to trigger this; simply set the layer weight via script when you want the action to start:

// Example: Fading in the upper body layer when firing a weapon
void Update() {
    if (Input.GetButtonDown("Fire1")) {
        animator.SetLayerWeight(1, 1.0f); // Set UpperBody layer to full influence
        animator.Play("Shoot", 1);        // Play in layer index 1
    }
}

By isolating the skeletal influence, your character can now aim, reload, or wave while maintaining perfect, fluid movement in their legs.

Key Takeaway: Use Avatar Masks within secondary Animation Layers to isolate specific body parts, allowing you to blend multiple animations simultaneously without interrupting locomotion.