Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Animation Plays In Preview But Not When Playing Game

I made a simple animation for a sword gameobject to constantly slowly move up and down while the player character is standing still.

My sword has an Animator component attached:

see here

The Animator Controller is also very simple, with this animation being attached to my default state:

see here

The animation plays just fine in the preview mode of the Animation window. But when I run my game, the animation does not play at all, the sword just stands still instead of moving.

What is the cause of this problem?

like image 597
Blaperile Avatar asked Dec 05 '15 18:12

Blaperile


People also ask

Why are my animations not playing Unity?

Animation not playing​This could be due to the Animation being unable to find the correct child / parent transforms if the Animator is on the wrong game object. Unity automatically rebinds animations for you if they are missing, so it will not appear as an error within Unity.


2 Answers

I finally solved the problem. It turns out that all I needed to do was turn off "Apply Root Motion" on my Animator for it to work properly.

like image 163
Blaperile Avatar answered Oct 11 '22 08:10

Blaperile


In case you are testing out on an Android Device I would suggest you to go to Build Settings > Player Settings > Other Settings > Uncheck "Static Batching". Build and deploy apk on your phone. Animations should work smoothly now.

like image 26
knightcube Avatar answered Oct 11 '22 06:10

knightcube