Animator
The Animator class is a core component in Unity for managing animations. It works with the Animator Controller to manage states and transitions in a state machine, enabling complex animation setups. This class provides a variety of methods and properties to control animations on GameObjects, essential for dynamic and interactive game environments.
Properties
Indicates if the Animator can be optimized for performance.
Checks if the Animator controls a humanoid model.
Determines if the Animator's animation data contains root motion.
Provides the scale of the humanoid Avatar in meters.
Checks if the Animator is initialized and ready to control animations.
Returns the GameObject's position change during the last frame.
Provides the rotation difference of the GameObject during the last frame.
Gives the velocity vector of the GameObject controlled by the Animator.
Returns the angular velocity vector of the GameObject.
Provides the position of the root of the GameObject controlled by the Animator.
Offers the rotation of the root of the GameObject controlled by the Animator.
Controls whether root motion in animations should be applied to the GameObject.
Indicates if the Animator has a transform hierarchy.
Represents the gravity weight based on current animations being played.
Allows getting or setting the position of the body mass.
Lets you get or set the rotation of the body mass.
Controls feet stabilization for plant and IK feet.
Represents the total number of layers within the Animator.
Pertains to the count of parameters in the Animator Controller.
A blend variable for calculating the position of each foot during a transition.
Indicates the current weight of the pivot, as determined by foot animations.
Offers the current position of the pivot in the avatar root, relative to world space.
Indicates whether the character is currently matching a target via script.
Allows manipulation of the Animator's playback speed.
Gets the target position for the MatchTarget function.
Fetches the target rotation for the MatchTarget function.
Refers to the root Transform of the humanoid Avatar in the animator.
Gets the current playback time of the Animator recorder.
Represents the start time of the first frame of the Animator recorder.
Provides the stop time of the last frame of the Animator recorder.
Indicates whether any playable graphs are attached to the Animator.
Controls whether the mass center is affected by all layers or only the base layer.
Provides the position of the bottom of the left foot relative to the root.
Represents the position of the bottom of the right foot relative to the root.
Controls whether warnings are logged for issues with AnimatorController setup.
Dictates whether the Animator is allowed to emit events.
Keeps the current Animator state and its time when the GameObject is disabled.
Writes default values into the GameObject when the animator component is disabled.
Methods
Retrieves a float parameter from the Animator.
Parameters
name
The name of the parameter to retrieve.
Returns
The float value of the specified parameter.
Sets the value of a float parameter.
Parameters
name
Name of the parameter.
value
The value to be set.
Returns
This method doesn't return a value.
Retrieves the value of a boolean parameter in the Animator.
Parameters
name
Name of the parameter.
Returns
The current state (true or false) of the specified parameter.
Sets the value of a boolean parameter in the Animator.
Parameters
name
Name of the parameter.
value
The value to be set.
Returns
This method doesn't return a value.
Fetches the value of an integer parameter in the Animator.
Parameters
name
Name of the parameter.
Returns
The current state of the specified parameter.
Assigns an integer value to an integer parameter in the Animator.
Parameters
name
Name of the parameter.
value
The value to be set.
Returns
This method doesn't return a value.
Activates a trigger parameter to change the animator's state.
Parameters
name
Name of the trigger parameter.
Returns
This method doesn't return a value.
Clears a trigger parameter.
Parameters
name
Name of the trigger parameter to reset.
Returns
This method doesn't return a value.
Checks if a parameter is controlled by a curve.
Parameters
name
The name of the parameter to check.
Returns
True if the parameter is controlled by a curve, false otherwise.
Sets a target position for the character's head to look at.
Parameters
lookAtPosition
Vector3Position for the character to look at.
Returns
This method doesn't return a value.
Sets the weights for the head and body parts to look at a position.
Parameters
weight
The weight by which the body parts follow the lookAtPosition.
Returns
This method doesn't return a value.
Retrieves the name of a layer by its index.
Parameters
layerIndex
The index of the layer.
Returns
The name of the layer.
Finds the index of a layer by its name.
Parameters
layerName
The name of the layer.
Returns
The index of the layer.
Gets the weight of a layer, defining its influence on the final animation.
Parameters
layerIndex
The index of the layer.
Returns
The weight of the layer.
Sets the weight of a layer, adjusting its influence on the final animation outcome.
Parameters
layerIndex
The index of the layer.
weight
The weight to set for the layer.
Returns
This method doesn't return a value.
Returns the count of AnimatorClipInfo instances for the current layer.
Parameters
layerIndex
The index of the layer.
Returns
The count of AnimatorClipInfo instances.
Gets the count of AnimatorClipInfo for the next layer the animator will transition to.
Parameters
layerIndex
The index of the layer.
Returns
The count of AnimatorClipInfo instances for the next layer.
Checks if the animator is in a transition between animations in the state machine.
Parameters
layerIndex
The index of the layer.
Returns
True if the animator is in transition, false otherwise.
Interrupts automatic target matching, allowing manual control.
Returns
This method doesn't return a value.
Gradually blends from the current animation to another over a fixed time.
Parameters
stateName
The name of the state to transition to.
fixedTransitionDuration
The duration of the transition.
Returns
This method doesn't return a value.
Writes default values to the Animator, resetting runtime modifications.
Returns
This method doesn't return a value.
Transitions from the current state to another over a relative duration.
Parameters
stateName
The name of the state.
normalizedTransitionDuration
Duration of the transition relative to animation length.
layer
Index of the layer.
normalizedTimeOffset
Adjusts the starting point of the transition.
Returns
This method doesn't return a value.
Plays an animation state at a specified time scale, unaffected by Animator speed.
Parameters
stateName
The name of the state to play.
layer
The layer index.
Returns
This method doesn't return a value.
Plays an animation state, allowing direct control over animation playback.
Parameters
stateName
The name of the state.
layer
The layer index.
Returns
This method doesn't return a value.
Begins animator playback mode, useful for testing Animator functionality.
Returns
This method doesn't return a value.
Stops animator playback mode initiated by StartPlayback.
Returns
This method doesn't return a value.
Starts recording the Animator in play mode for analysis or replaying sequences.
Parameters
frameCount
Number of frames to record.
Returns
This method doesn't return a value.
Stops recording started by StartRecording, controlling recording duration.
Returns
This method doesn't return a value.
Checks if a specific state exists within a layer of the Animator.
Parameters
layerIndex
The index of the layer.
stateID
The ID of the state to check for existence.
Returns
True if the state exists in the specified layer, false otherwise.
Manually advances the Animator state machine by a specified amount of time.
Parameters
deltaTime
The amount of time to advance the state machine.
Returns
This method doesn't return a value.
Resets the Animator to its default state, removing all runtime modifications.
Returns
This method doesn't return a value.
Applies built-in root motion from animation clips, if present.
Returns
This method doesn't return a value.
Converts a string into a hash ID for efficient parameter identification.
Parameters
name
The string to convert into a hash ID.
Returns
The hash ID of the string.