Game Toolkit for Unity
Learn more about animation state machines and what you can use them for.
Animation state machines are Unity state machine behaviours that are added to animator states. They’re used in animator controllers, e.g. to react on state changes.
An animation state machine can be added to a state by selecting a state and clicking on Add Behaviour > AnimationStateMachineComponent.
You can learn more about machine components in general and their basic settings here.
An animation state machine is started by state machine and state change callback functions.
Started when transitioning from another state machine’s state to the state’s state machine. It’s implemented in the component’s OnStateMachineEnter function.
This start type will automatically initialize the following local variables.
The State Machine Enter start type can optionally check the state machine’s path hash the OnStateMachineEnter function was called with. This can be used to e.g. only start the machine when the path hash matches a defined value.
This start type can be used to change an animator parameter when entering a state machine. Use a Play Mecanim Animation node to change parameters of an animator.
Started when transitioning from the state’s state machine to another state machine’s state. It’s implemented in the component’s OnStateMachineExit function.
The State Machine Exit start type can optionally check the state machine’s path hash the OnStateMachineExit function was called with. This can be used to e.g. only start the machine when the path hash matches a defined value.
This start type can be used to change an animator parameter when leaving a state machine. Use a Play Mecanim Animation node to change parameters of an animator.
Started when the state machine starts evaluating the state (i.e. when entering the state). It’s implemented in the component’s OnStateEnter function.
The State Enter start type can optionally check the layer index the OnStateEnter function was called with. This can be used to e.g. only start the machine when called from a defined layer.
This start type can be used to play an audio clip when entering a state. Use a Play Sound node to play an audio clip.
Started when the state machine ends evaluating the state (i.e. when leaving the state). It’s implemented in the component’s OnStateExit function.
The State Exit start type can optionally check the layer index the OnStateExit function was called with. This can be used to e.g. only start the machine when called from a defined layer.
This start type can be used to play an audio clip when leaving a state. Use a Play Sound node to play an audio clip.
Started immediately before it updates the animator’s internal IK (inverse kinematics) system but after Animator IK, when the state is active and the state’s layer has an IK pass. It’s implemented in the component’s OnStateIK function.
The State IK start type can optionally check the layer index the OnStateIK function was called with. This can be used to e.g. only start the machine when called from a defined layer.
This start type can be used to set the positions of the IK goals and their respective weights. Use an Animator Weight node to set the position and weight IK goals.
Started each frame the state is active, after Animator Move. It’s implemented in the component’s OnStateMove function.
The State Move start type can optionally check the layer index the OnStateMove function was called with. This can be used to e.g. only start the machine when called from a defined layer.
This start type can be used to move a game object based on root motion. Use a Store Parameter node to store parameters from the animator controller into variables and use them in one of the various Movement nodes (e.g. a Move node) to move the game object.
Started each frame the state is active, except the first and last frame (i.e. when State Enter and State Exit are used). It’s implemented in the component’s OnStateUpdate function.
The State Update start type can optionally check the layer index the OnStateUpdate function was called with. This can be used to e.g. only start the machine when called from a defined layer.
This start type can be used to play an audio clip when while being in a state. Use a Play Sound node to play an audio clip – additionally, you can check the local float variable normalizedTime (passed as start variable) to check the current play position of the state and only play the sound at specific points.