Pro-Only: Animancer Lite allows you to try out this feature in the Unity Editor, but it will not be available in runtime builds unless you purchase Animancer Pro.
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.
Example
Most operations involving layers are accessed via the AnimancerComponent.Layers
property:
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);
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.
Details
- 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
ArgumentOutOfRangeException
if 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 theAnimancerComponent.Layers.Capacity
to a higher value (or consider setting the staticAnimancerPlayable.LayerList.defaultCapacity
or usingSetMinDefaultCapacity
). - Changing Layers: if an
AnimancerState
already 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 theirAnimancerState.LayerIndex
property directly. - 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. - If you want to play the same animation on multiple layers at once, you will need to create multiple states for it and register them with different Keys (or not register them at all and simply keep references to them yourself).
Blending
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 anAnimancerState
and you can use theirStartFade
method to Fade them in and out over time.StartFade
only affects the layer you call it on and there is noCrossFade
for 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 = 0
by default. However, callingAnimancerComponent.Play
targeting a layer at 0 weight will automatically set itsWeight = 1
. Similarly, Cross Fading will actuallyPlay
the animation atWeight = 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
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 usingAnimancerComponent.Layers.SetMask
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.IsAdditive
.