Graph Structure

The Playables API which Animancer is built around works using a tree-like structure of nodes known as a PlayableGraph. The following diagram shows how Animancer arranges the graph connections:

  • The root AnimancerPlayable can have multiple AnimancerLayers connected to it.
  • Each AnimancerLayer can have multiple AnimancerStates connected to it.
  • MixerStates are a type of AnimancerState which can have other states connected to them, including other mixers.
  • Most of the time a new state is connected to its parent when created, but if you need to you can use AnimancerState.SetParent to reconfigure the graph dynamically.

Playable Graph Visualizer

The Playable Graph Visualizer is a tool made by Unity for displaying PlayableGraphs. If you have it in your project, the Live Inspector context menu will include a function to open the visualizer and set it to show the current graph.

Iterating

All of the core classes in Animancer implement IEnumerable<AnimancerState>, meaning that you can use them in foreach loops to iterate through their child states:

private void LogAllStates(AnimancerComponent animancer)
{
    Debug.Log("Logging all states in " + animancer);

    foreach (var state in animancer)
    {
        Debug.Log("Found state " + state);
        LogAllStates(state, 1);
    }
}

private void LogAllStates(AnimancerState state, int indent = 0)
{
    foreach (var childState in state)
    {
        var message = "Found child state " + state;
        for (int i = 0; i < indent; i++)
            message = "    " + message;

        Debug.Log(message);
        LogAllStates(childState, indent + 1);
    }
}