Animator Controllers

This is a Pro-Only Feature: you can try it out in the Unity Editor with Animancer Lite, but it will not be available in runtime builds unless you purchase Animancer Pro.

Animancer does not require the use of Animator Controller assets, but it does support them via the ControllerState class (and its children). This means that instead of putting everything a character needs in one massive Animator Controller like you would in Mecanim, you have several other options for structuring your project which are demonstrated in various examples:

  • The Hybrid Basics example demonstrates how you can use a main Animator Controller for some tasks and individual separate AnimationClips for others.
  • The Hybrid Mini Game example demonstrates a more complex form of the same thing.
  • The Linear Blending example compares the use of a Blend Tree inside an Animator Controller with the use of a Mixer.
  • The 3D Game Kit example demonstrates how you can utilise multiple single purpose Animator Controllers alongside separate AnimationClips, simply choosing whichever is more appripriate for each given task.

Usage

ControllerStates are usually set up in the Inspector using Controller Transitions, but they can also be created manually.

Normally when using an Animator Controller, you would access it via various methods on the Animator component such as Play, CrossFade, GetCurrentAnimatorStateInfo, and get/set for all parameter types. But when using a ControllerState, you instead need to access it via the ControllerState.Playable:

void ControllerStateExample(ControllerState state)
{
    // Play the "Idle" state:
    state.Playable.Play("Idle");

    // Transition to the "Walk" state over 0.25 seconds:
    state.Playable.CrossFade("Walk", 0.25f);

    // Set the "MoveSpeed" parameter:
    state.Playable.SetFloat("MoveSpeed", 0.5f);

    // Set the "Attack" trigger:
    state.Playable.SetTrigger("Attack");
}

If you are using a ControllerState.Transition you will need to first access its state, i.e. transition.State.Playable.... Note that the State will only be created the first time the transition is passed into the AnimancerComponent.Play method, so you will get a NullReferenceException if you attempt to use it before that.

Manual Creation

If you do not want to use a Controller Transition, you can create one yourself using code:

  1. Create a new ControllerState. All constructors require you to provide a RuntimeAnimatorController reference.
  2. Store a reference to that state in a field and/or set its Key to register it in the internal dictionary. The RuntimeAnimatorController itself or its name would make an acceptable key.
  3. Play that state either by passing it into AnimancerComponent.Play if you have a reference to it or using the key you registered it with.

Parameter Controller States

Animancer includes several classes which inherit from ControllerState to wrap specific parameters of the AnimatorController in C# properties:

Using them is very similar to the base class, but you also specify which parameter(s) you want to target in the constructor and can then get and set those parameters via their Parameter properties.

  • This has the added benefit of verifying that the parameter actually exists on startup to make it easier to detect bugs.
  • Using their Transitions gives you a helpful dropdown menu in the Inspector for selecting the parameter name(s) instead of hard-coding them as Magic Strings. The Linear Blending example demonstrates the use of a Float1ControllerState.Transition.
  • You can easily make your own copies of the scripts containing these classes if you want to adapt them for other parameter types and purposes.