Layers

When you play an animation, it stops all others (or Fades them out). More specifically, it stops all other animations on the same layer without affecting animations on other layers. This allows you to play multiple separate animations at the same time, using the layers to determine how they combine to form the final output.

Most operations involving layers are accessed via the AnimancerComponent.Layers property:

void LayerExample(AnimancerComponent animancer, AnimationClip clip)
{
    // Create a state on the default layer 0 and play it.
    // If a state for that animation already existed, leave it on its current layer.
    animancer.Play(clip);

    // Create a state on layer 1 and play it.
    // If a state for that animation already existed, move it to layer 1.
    // If layer 1 did not already exist, accessing "Layers[1]" creates it.
    animancer.Layers[1].Play(clip);

    // Fade out the layer to make it stop affecting the character.
    // Playing something on the layer will automatically fade it in again.
    // DO NOT fade out the state. That would not blend correctly.
    animancer.Layers[1].StartFade(0, 0.25f);
}

The Layers samples demonstrate how to use them in more detail.

Details

  • New Layers: if you specify a layer that does not exist, it will automatically be created (along with every layer before it).
  • Changing Layers: if an AnimancerState already exists for the animation and you try to play it on a different layer, the state will be clones on the new layer as demonstrated by the Dynamic Layers sample.
  • Names: you can call SetDebugName on a layer to give it a name that will be displayed in the Inspector, however these names do not exist at runtime so any calls to that method will be automatically compiled out of runtime builds.

Blending

Warning: be sure to fade out the layer, not the state. Otherwise it won't blend correctly.

There are several different factors which determine how the output of each layer is combined to form the final result:

  • Weight: each layer has a Weight just like an AnimancerState and you can use their StartFade method to Fade them in and out over time.
    • StartFade only affects the layer you call it on and there is no CrossFade for layers because it's not common to swap them like that, however you can simply fade one in and the rest out if you need to.
    • Layers start at Weight = 0 by default. However, calling AnimancerComponent.Play targeting a layer at 0 weight will automatically set its Weight = 1.
    • Similarly, Cross Fading will actually Play the animation at Weight = 1 immediately and fade the layer in instead of fading the animation.
    • If you want a layer to stop affecting the final output, you can simply fade its weight to 0 (or set its Weight = 0 to do it instantly).
  • Masks: each layer can be given an AvatarMask to determine which bones it affects. You can create a mask using the Assets/Create/Avatar Mask menu function and then assign it to a layer using animancerComponent.Layers[x].Mask = mask so that animations on that layer will only affect the parts of the model included in the mask.
  • Additive Blending: by default, each layer will override the previous layer, entirely replacing its output. You can instead have a layer add its animations on top of the previous layer using animancerComponent.Layers[x].IsAdditive = true.

Other Pages

Weighted Mask Layers Control the individual weight of each bone affected by a layer.