When you play an animation it stops all others (or Fades them out). More specifically, it stops all other animations on the specified 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 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" creates it. animancer.Layers.Play(clip);
Below is a video of the Layers example which shows this feature in action. If the Action is performed while the character is Idle, it is played on the default layer so that it controls the full body. But if it is performed while the Run animation is playing, then the Action is played on another layer which is masked to only affect the upper body, so the legs continue running while the upper body acts independantly.
- Max Layer Count: if you specify a layer that does not exist, it will automatically be created (along with every layer before it). By default, Animancer will throw an
ArgumentOutOfRangeExceptionif you try to create more than 4 layers, however this is only a general safety measure because most situations will not need more than that. If you do actually need more than that, you can simply set the
AnimancerCmponent.Layers.Capacityto a higher value (or consider setting the static
- Changing Layers: if an
AnimancerStatealready exists for the animation and you specify a different layer, the state will be moved to that layer. You can also move states to a different layer by setting their
- Names: you can call
SetNameon 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.
- If you want to play an animation on multiple layers at once, you will need to create multiple states for it and register them with different Dictionary Keys (or not register them at all and simply keep references to them yourself).
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
Weightjust like an
AnimancerStateand you can use their
StartFademethod to Fade them in and out over time.
StartFadeonly affects the layer you call it on and there is no
CrossFadefor layers because it is 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 = 0by default. However, calling
AnimancerComponent.Playtargeting a layer at 0 weight will automatically set its
Weight = 1. Similarly,
Playthe animation at
Weight = 1immediately 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
Weight = 0to do it instantly).
- Masks: each layer can be given an
AvatarMaskto 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.SetLayerMaskso 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