I have an issue with Animator.Play. I have set up an animation the same way I have set up other successful animations that are currently working. Referring to the code below, I am calling Animator.play from the same game object that contains the animator and my animation. When I do this, the animation does not play. Placing a call to my Animate() function does not play my animation. OnAnimationStarted and OnAnimationFinished are both events triggered from within my animation on the first frame and the last frame respectively. I see the “Calling Play Animation” Debug line in the console, and I have confirmed through Visual Studio debugging that the animation exists in my Animator component and that it is named / spelled correctly in code. I do not see any “Animation Started” or “Animation Finished” lines in the console, and my animation simply does not play when called. I use this exact same method elsewhere in my project, and the animation plays and triggers the events as expected. I am at a loss as to why this implementation does not work the same way as the others. Does anybody have any insight into this issue?
Animator m_animator;
public void Animate()
{
Debug.Log("Calling Play Animation");
m_animator = this.gameObject.GetComponent<Animator>();
m_animator.Play("AwardAnimation");
}
void OnAnimationStarted()
{
Debug.Log("Animation Started");
}
void OnAnimationFinished()
{
Debug.Log("Animation Finished.");
}