Creating Custom States

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.

You can implement your own state type by inheriting from AnimancerState (or any type derived from it). When doing so it is recommended that you start with the template below to include the common constructors.

Note that setting the base AnimancerNode._Playable is mandatory, otherwise you will get the following exception in various places throughout the system: ArgumentException: The playable passed as an argument is invalid. To create a valid playable, please use the appropriate Create method.

using Animancer;
 
public sealed class MyState : AnimancerState
{
    // If you use this constructor you will need to use SetParent to connect
    // the playable to the graph.
    public MyState(AnimancerPlayable root)
    {
        // Set the playable. THIS IS MANDATORY.
        // For example, ClipState has an AnimationClip parameter and calls:
        _Playable = AnimationClipPlayable.Create(graph, clip);
    }

    // Extra constructors for convenience.

    // Note that AnimancerComponent can be implicitly cast to
    // AnimancerLayer to use their default layer in this constructor.
    // This is the most commonly used constructor.
    public MyState(AnimancerLayer layer)
        : this(layer.Root)
    {
        layer.AddChild(this);
    }

    // This one is for AnimationMixers so you can specify any index you want.
    public MyState(AnimancerNode parent, int index)
        : this(parent.Root)
    {
        SetParent(parent, index);
    }
}