Waiting

Both systems support several different possible approaches to waiting until an animation ends before running some code:

  • Both can make use of Animation Events, though they are not really the best tool for specifically waiting until the animation ends because it would be quite tedious to set up an event on every animation.

Mecanim

  • Constantly check which state is playing using Animator.GetCurrentAnimatorStateInfo.
    • This requires the state to have an Exit Time transition to actually exit the state and requires you to work with hash codes which aren't particularly user-friendly in order to determine which state is which.
    • You also need to be aware that it won't enter the desired state immediately, so you actually need to wait for it to enter that state then wait for it to exit.
  • Same as above, but check the value of the state’s normalizedTime property instead of relying on an Exit Time transition.
  • Make a StateMachineBehaviour script that does essentially the same thing as the previous two options by overriding OnStateExit or OnStateUpdate, add it to the state in question.

Animancer

  • When you call Play it returns an AnimancerState. Simply register a callback delegate to the OnEnd event of that state.
  • If you are inside a coroutine you can yield return that state to wait for it to end.
  • Store the state in a field and constantly check its Time, or NormalizedTime. If you're worried about other scripts stopping it, you can also check its IsPlaying property.

The End Events page covers these options in greater detail.