- Home /
Animation never officially completes
I am using Mixamo characters in my Unity game. I am trying to programmatically loop the character walking. My code is as follows: private Animator anim;
// Use this for initialization
void Start () {
// Get the animator component.
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update () {
if (!anim.GetCurrentAnimatorStateInfo (0).IsName ("Walking")) {
anim.Play ("Walking");
}
}
But the animation doesn't play again after the first loop. You can see in the inspector that it hangs at the very end. It stays in this state for perpetuity.
Answer by StickyHoneybuns · Feb 02, 2018 at 04:46 PM
Go to the imported model walking animation of your character and in the inspector scroll down and click the loop box associated with it. This will allow it to loop when started. Also, you have not created a loop in update. You are telling it to only play once. This is fine and all you need to do is click the loop box as I mentioned.
$$anonymous$$y thinking was that because update is called after every frame, this would effectively be a loop (since play would continuously be invoked). Evidently, this is not true. Do you have any insight into what the flaw in my logic is?
I'm accepting the answer since this is the appropriate fix, but would appreciate some insight into why my previous logic is wrong.