class in UnityEngine
/
Inherits from:Behaviour
/
Implemented in:UnityEngine.AnimationModule
Manages, controls, and evaluates the animation of a GameObject.
The Animator is the main Component in the Mecanim animation system. The Animator evaluates Animation Clips and manages Animator States in Animator State Machines.
Control the Animator with an AnimatorController
Typically, you configure an Animator with an AnimatorController asset. This asset determines which animation plays. To learn how to build an AnimatorController, consult Animator Controller.
Once configured with an AnimatorController, you can influence the flow of the state machine through the following methods:
For more advanced use cases, you can control an Animator with the Playables API.
Animator execution
By default, an Animator evaluates on each frame, following Time.deltaTime. On a frame where none of the paired Renderers are visible, the Animator only updates the position of the root GameObject. No other transforms or component properties are updated.
To change this default behavior, use one of the following methods:
Root Motion
Root Motion refers to the cumulative displacement of a GameObject hierarchy. For more information, consult How Root Motion works.
When Animator.applyRootMotion is true, the Animator does the following on each frame:
- Automatically calculates the displacement of the Root joint for the frame.
- Adds this displacement to the position and rotation of the GameObject with the Animator Component.
For information on how to override this behavior, consult Scripting Root Motion.
Generic and Humanoid animation
The Animator evaluates two types of Animation Clips: Generic and Humanoid.
A Generic animation clip contains multiple animation curves where each curve animates a property of either a Transform or a MonoBehaviour. A Generic clip is authored for and animates a specific GameObject hierarchy. If you attempt to use a Generic clip on a different GameObject hierarchy, it might not play back as expected.
A Humanoid animation clip is designed for human or human-like bipedal GameObject hierarchies. To use a Humanoid clip on a bipedal GameObject hierarchy, you must configure an Animator with a Humanoid Avatar.
You can reuse the same Humanoid clip on any Animator configured with a Humanoid Avatar to reduce runtime memory usage and build size. However, this increases CPU usage. Expect a 15 to 20 percent increase in the time spent animating a GameObject hierarchy when evaluating Humanoid AnimationClips.
To determine if the benefits of using Humanoid clips is worth the cost in CPU peformance, perform your own experiments on your target platforms.
It is recommended that you exclusively use Humanoid clips or Generic clips.
Inverse Kinematics
The Animator class includes inverse kinematics methods that you can use to configure dynamic interactions between a humanoid and scene objects. Consult Inverse Kinematics for steps and an example.
SetTarget
When you want a character to interact with an object that is too far to reach with inverse kinematics, use Animator.SetTarget to adjust the position and rotation of a character over time to ensure its hand or foot reaches the object.
Bindings and performance
To track the properties that an Animator must write to, the Animator Component builds an internal collection of bindings. Each binding is built from the EditorCurveBinding of each AnimationClip associated with the Animator through assets and custom graphs.
From this collection of bindings, the Animator builds an internal AnimationStream which defines the size of the buffers to allocate for AnimationClip evaluation.
After an Animator allocates its buffers, it iterates through each binding and searches for the appropriate Component in the corresponding GameObject hierarchy. The Animator keeps a reference to each binding so it can be written to in subsequent frames.
This operation is called Rebinding, and it can be triggered by different events:
Avoid and minimize Rebind
Use the following strategies to avoid and minimize the occurrence of the Rebind operation: