- Home /
Detecting last frame of animation, without StateMachineBehaviours or Animation Events
I have a system in my game which will frequently need to execute arbitrary code on the final frame of an animation. I'm having trouble finding an adequate way to detect the final frame of this animation & fire the code.
The two suggestions I have seen so far are using the StateMachineBehaviour's OnExit, and Animation Events. However, to the best of my knowledge neither of these will suit my purposes. OnExit only fires on state transitions, but what I need is to fire on the final frame of an animation that may or may not ever transition. Animation Events, meanwhile, require marking up the final frame of every possible animation I'd want to use, and giving their objects a component that hooks into the code I want to call, which is an untenable amount of overhead.
All I want to do is to write a coroutine that takes a variable animation and says "Play this animation, and yield until it reaches its final frame." Is there a lightweight way to do this?