architecture
[Mecanim] Master Animator Animation Completion
Solution
Unity 2021.x - Unity 6.3.x
Published Fri, Mar 13
Detecting the precise moment a non-looping animation concludes within an Animator Controller is a frequent requirement. This is essential for triggering follow-up actions like enabling AI behavior or instantiating objects immediately after your animation finishes playback.
Detect animation completion using a StateMachineBehaviour script or AnimationEvents.
- Create a new script inheriting from StateMachineBehaviour.
- Override the
OnStateExitmethod to execute logic when the state concludes. - Attach your state machine behavior script to the specific
AnimatorStatewithin theAnimator Controller. - Alternatively, navigate to the Animation Window and locate your animation.
- Move the playhead to the final frame and click Add Event.
- Select a public method from a component on the
GameObjectto trigger upon completion.
Additional Tips
- Use StateMachineBehaviour for logic decoupled from specific scripts.
AnimationEventsrequire the target script to be on the sameGameObject.- Ensure
Animatortransitions do not prematurely triggerOnStateExitduring blending.
TL;DR
Animation completion in an Animator can be detected by either implementing a StateMachineBehaviour script on the animation state or by utilizing AnimationEvents directly within the animation clip.
Related Posts Haven't quite found a solution to your problem? We think these posts might help you.
[Key Press] Stop Input.GetKeyDown Double Triggers[Vector Graphics] Referencing SVG Assets via C# Scripts[Animator] Erases MaterialPropertyBlock: Restore Visuals
Content inspired by a Unity discussion post.