8

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?

frogatto
  • 28,539
  • 11
  • 83
  • 129
Blaperile
  • 141
  • 1
  • 1
  • 6
  • How are you trying to call the Animation? – Aizen Dec 05 '15 at 19:03
  • @Aizen I put my animation (IdleSword) in the default state of my Animator Controller. Doesn't that mean it's called automatically? Nevertheless, I've tried calling the animation manually from a script with `GetComponent().Play("IdleSword")` and it does nothing either. – Blaperile Dec 05 '15 at 20:23
  • Maybe I am wrong, but I think that to call directly `GetComponent().Play("IdleSword")`, you need to have a transition from Any State to IdleSword. – Ricardo Reiter Dec 07 '15 at 18:44
  • Your IdleSword is market to Loop? There is a checkbox in the animation properties. – Ricardo Reiter Dec 07 '15 at 18:46
  • @RicardoReiter Yes it's marked to loop. I just tried adding a transition from Any State to IdleSword but it made no difference. My Animator Controller does show that the state is running (the blue progress bar beneath it), but the animation itself isn't playing. – Blaperile Dec 08 '15 at 11:51
  • There is some script attached to the Sword Object? – Ricardo Reiter Dec 08 '15 at 12:27

2 Answers2

6

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.

Blaperile
  • 141
  • 1
  • 1
  • 6
2

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.

knightcube
  • 139
  • 1
  • 13