Unity's main animation system revolves around Animator Controllers which encapsulate some limited logic with animations. That system has some notable problems which Animancer avoids, but there are still some cases where you might want to use Animator Controllers and it's possible to use both systems alongside each other.
Situation | Recommended Approach |
---|---|
I'm starting a new project. | Use Animancer without Animator Controllers. |
I have a simple Animator Controller. | Use the Conversion page as a guide to replace it with Animancer. |
I have a complex Animator Controller. | [Pro-Only] Follow the Integration guide below. |
I want to mix multiple Animator Controllers. | [Pro-Only] Use Controller States. |
Integration
If you have a complex Animator Controller based system and you want to use Animancer to play some extra animations on top of it, there are two main ways they can work together:
Native | Hybrid |
---|---|
Play the Animator Controller normally and use Animancer separately. | Use a HybridAnimancerComponent to play the Animator Controller within Animancer. |
Assign your Animator Controller to the Animator .
|
Leave the Controller blank on the Animator .
|
Use a regular AnimancerComponent .
|
Use a HybridAnimancerComponent and give it your Animator Controller.
|
Generic Rigs work fully. |
Generic Rigs work fully. |
Humanoid Rigs can't smoothly blend into Animancer. It will instantly snap between them as demonstrated in the Hybrid Character sample. |
Humanoid Rigs work fully. |
The Animator Controller will always be running in the background, even when Animancer is fully overriding the output (which may waste performance). | The Animator Controller will stop executing while Animancer plays other animations. |
The Hybrid Character sample also demonstrates how to use both of those approaches and the differences between them.
Native
This approach is basically just Unity's regular way of using Animator Controllers with Animancer on top. Note the limitations listed in the Integration table.
Scripts that control the Animator component continue to work normally.
[SerializeField] private Animator _Animator;
void RegularAnimatorControlExample()
{
// Play the "Idle" state in the Animator Controller:
_Animator.Play("Idle");
// Set the "MoveSpeed" parameter in the Animator Controller:
_Animator.SetFloat("MoveSpeed", 0.5f);
}
And other scripts can play animations with Animancer to have it take over temporarily.
[SerializeField] private AnimancerComponent _Animancer;
[SerializeField] private AnimationClip _SeparateAnimation;
void NativeControllerExample()
{
// Play a separate animation not included in the Animator Controller:
_Animancer.Play(_SeparateAnimation);
// Stop all separate animations and return to the Animator Controller:
_Animancer.Stop();
// Fade out Animancer's Layer 0 over 0.25 seconds and return to the Animator Controller:
_Animancer.Layers[0].StartFade(0, 0.25f);
}
The Hybrid Character sample demonstrates this approach in more detail.
Hybrid
The HybridAnimancerComponent
allows you to play an Animator Controller inside Animancer. Note the limitations listed in the Integration table.
Using it is almost the same as the Native approach, except you need to control the HybridAnimancerComponent
instead of the Animator
. It has most of the same properties and methods so all you need to do to convert a script to this approach is replace any Animator
references with HybridAnimancerComponent
. For example:
// Replace this:
[SerializeField] private Animator _Animator;
// With this:
[SerializeField] private HybridAnimancerComponent _Animator;
// Consider leaving the field name unchanged.
// It's now incorrect, but this minimises the number of lines you need to change in the file.
// This makes it easier to find important changes in a version control system.
// Anything you would do with the Animator works the same with the HybridAnimancerComponent.
void HybridAnimancerComponentExample()
{
// Play the "Idle" state in the Animator Controller:
_Animator.Play("Idle");
// Set the "MoveSpeed" parameter in the Animator Controller:
_Animator.SetFloat("MoveSpeed", 0.5f);
}
If the script uses serialized fields like that, you will also need to re-assign the HybridAnimancerComponent
reference in the Inspector.
Then you can play animations with Animancer to have it take over and call PlayController
to return to the Animator Controller.
[SerializeField] private HybridAnimancerComponent _Animancer;
[SerializeField] private AnimationClip _SeparateAnimation;
void HybridControllerExample()
{
// Play a separate animation not included in the Animator Controller:
_Animancer.Play(_SeparateAnimation);
// Return to the Animator Controller using the transition settings in the Inspector:
_Animancer.PlayController();
}
Unfortunately, not all features are supported so if you need to use something that's missing, it probably isn't supported.
The Hybrid Character Sample demonstrates this approach in more detail.