Animation Controller

The animation controller component is used to apply the Animation Graph Assets to the object.

Select the node in Hierarchy panel where you need to apply the animation graph, and then click Add Component -> Animation -> Animation Controller below in Inspector panel to add an animation controller component to the node.

add-animation-controller

Note: Because the Marionette animation system and the old animation system cannot be used together, animation controller components also cannot be mounted on the same node as animation components or skeletal animation components.

Properties

animation-controller

PropertiesDescription
GraphAdded animation-graph resource, default is empty

Programmatically Controlling Animation Graphs

The animation controller component provides a number of methods for controlling the Animation State Machine of the animation graph at runtime.

MethodDescription
getVariablesGet all variables and their names/types/values, etc.
setValueSet the value of the variable.getValue</td></tr><tr><td><code>getValue</code></td><td>Get the value of the variable.</td><td>getValue
getCurrentStateStatusGet the current state information.getCurrentStateStatus
getCurrentClipStatusesGet the current state of the clip.getCurrentClipStatuses
getCurrentTransitionGet the current state transition.getCurrentClipStatuses
getNextStateStatusGet information about the next state.getNextStateStatus</td></tr><tr><td><code>getNextClipStatuses</code></td><td>Get the status of the next animation clip.</td><td>setLayerWeight
setLayerWeightSet the weight of a certain animation-graph layer.
  • Variable Control

    For example, we have a variable in the Animation Graph Panel added several variables, the code can get and modify the value of the variables, the code example is as follows.

    1. // Get the animation controller component
    2. let animationController:animation.AnimationController = this.node.getComponent(animation.AnimationController)
    3. // Get all variables
    4. let variables= animationController.getVariables();
    5. // Get the value of the variable named 'vertical'
    6. let vertical: Number = animationController.getValue("vertical");
    7. // Change the value of the variable named 'vertical' to 1.0, which will calculate the conditional transition on the next update frame
    8. animationController.setValue("vertical", 1.0)

    Note: Variables for the animation state machine can currently only be added and removed in the Animation Graph Panel.

  • Get the current state

    Get the normalized progress of the current state of the state machine at layer 0, with the following code example.

    1. let states: animation.MotionStateStatus = animationController.getCurrentStateStatus(0)
    2. console.log(states.progress);
  • Get the current transition

    Gets information about the upcoming transition of the state machine at layer 0.

    1. let transition: animation.TransitionStatus = animationController.getCurrentTransition(0)
    2. console.log(transition.duration, transition.time)