Fading

As explained on the Playing Animations page, there are several different sets of parameters you can specify when calling AnimancerComponent.Play depending on whether you want it to immediately snap to the new animation or gradually fade it in over time while fading the previous animation out (known as "Cross-Fading").

Fading is not generally used for Sprite animations because they cannot be blended, however is very useful for Skeletal Animations because it allows a character model to smoothly transition from the ending pose of one animation into the starting pose of another animation without requiring both poses to be exactly the same. It also means that the transition can still be smooth if an animation is interrupted at any time.

The Playing and Fading example demonstrates the use of this feature in more detail.

Durations

Fading is supported in Animancer Lite, however the ability to specify a custom fade duration is a Pro-Only Feature so it will always use the default 0.25 seconds in runtime builds unless you purchase Animancer Pro.

void CrossFadeExample(AnimancerComponent animancer, AnimationClip clip)
{
    // Default 0.25 seconds fade duration.
    animancer.Play(clip, AnimancerPlayable.DefaultFadeDuration);

    // Fade over 0.8 seconds.
    animancer.Play(clip, 0.8f);

    // Fade for 20% of the new clip's duration.
    animancer.Play(clip, clip.length * 0.2f);
    animancer.Play(clip, 0.2f, FadeMode.NormalizedSpeed);

    // Fade for 10% of the old clip's duration.
    animancer.Play(clip, animancer.States.Current.Length * 0.1f);
}

The Play methods that take a fade duration also have a FadeMode parameter to determine exactly how it works. That parameter is optional and will use FadeMode.FixedSpeed if not specified so the following two lines will do exactly the same thing:

animancer.Play(clip, 0.25f)
animancer.Play(clip, 0.25f, FadeMode.FixedSpeed)

Note that the fade duration is entirely separate from the length of the animation, so if the fade is too long it might not even finish fading in by the time the animation ends.

Individual Fading

When you call the Play method with a fade duration, it internally calls AnimancerNode.StartFade on every animation. For example, if you have Idle, Walk, and Jump animations and you call Play(walk, 0.25f), it will call StartFade(1, 0.25f) on the walk state and StartFade(0, 0.25f) on the others. This means you can use StartFade to control individual states rather than only cross-fading all of them at once.

Since AnimancerLayer also inherits from AnimancerNode, this also means that you can fade entire Layers in and out. There is no CrossFade for layers because they are not commonly used in that manner, but you can achieve the same thing by calling StartFade(0, fadeDuration) to fade some layers out and StartFade(1, fadeDuration) to fade others in. The Layers example makes use of this feature to fade out the upper body layer once it is no longer needed so that the base layer can resume controlling the character's entire body.