End of animation clip using Animator (Mecanim)

I’m using Mecanim Aninator for my walks, run etc and all that works nicely driven from a C# script. Sometimes I need to start a one-shot animation and that also is not problem using Exit Time. However I need to know when the one-shot has ended from my script.

Any ideas how to do that?

The last answer in this page seems to answer the question pretty well. How can I check if an animation is playing or has finished? (Using Animator/C#) - Unity Answers You essentially need to poll the animation state until it is not the expected one. Mixamo also created a package that is free and can be hooked to different parts of the animation.

My suggestion is to create a system that will call that event whenever this situation is not true. I can probably do this if you poke me. I’m just going to make an animation event system that does this for you easily.

I had the same problem detecting the end of the clip. I prefer using Animator\Animation events.

It’s explained in the API documentation:
Unity - Manual: Events http://docs.unity3d.com/Manual/animeditor-AnimationEvents.html

if(stateInfo.IsName(“Hat”))
{
if(stateInfo.normalizedTime >= 0.99f)
{
//b_hat = false;
_animator.SetBool(“hat”, false);
}
}

But this is playing the animation again sometimes.

In animator set trigger “IsDestroy” and make connections between “Breake” and “Destroy” animation throw change trigger.
“Destroy” animation is empty, Just for triggering

 IEnumerator PlayBreak()
    {
        animator.SetTrigger("IsDestroy"); 
        animator.Play("Break"); 

        while (animator.GetBool("IsDestroy"))
        {
            yield return null;
        }

        GameObject.Destroy(this.gameObject);
    }