- Home /
Sprite animations won't export/run in a published build unless you play in editor first
It's a strange issue, but I've had it from Unity 4.3 and up, including the current 4.6 beta. It's a 2D game using many sprite animations, but if I just open the project and export a build, the animations won't play in the build. They just sit there frozen on the first frame. For example, the character is just sliding around. However any animation that has been "viewed" while playing in editor will from that point export fine in published builds. I really can't trust a published build, and as the game grows it seems crazy that I would have to run through the entire game making sure I've "seen" every animation before publishing a build? Is anyone else experiencing this bug?
Answer by grrlgglglr · Sep 27, 2014 at 06:53 PM
Same problem here, I can confirm that on Unity 4.5.3. I'm unable to figure out why this happens, but it looks like only objects that start out disabled suffer from this. Also, interestingly, not only does the animation freeze but rather the entire Animator component. I did some debugging and setting Animator parameters (e.g. with SetFloat
) and reading them back (`GetFloat`) doesn't even return the correct value, which is just frozen.
If you only had a handful of objects you should be able to work around this by making the object transparent or disabling only the sprite renderer, which is what I did for lack of a better solution.
However, if you really have many sprites as you mention, this workaround is kind of infeasible.
It's not much, but hope that helps, maybe someone will shed light on this soon since it's a rather serious bug.
UPDATE: From what I could gather, the problem comes down to transitions in Mecanim. For some reason, if you ever add a transition between sprite animation in an animation controller, it will break forever, even if you remove the transition afterwards. So another possible workaround would be not using state transitions ever and handling animations entirely in behavioral scripts. I'll get to working in a script that makes this a little less painful to manage until it gets fixed.
Thanks for the input grrlgglglr, that at least is something to possibly look into to, though definitely a workaround. I am pretty surprised that I don't hear a lot about this, as it directly affects your final builds and is pretty much a showstopper. The fact that I haven't heard much about it led me to think that it was some kind of local issue I was having with my project specifically - but it's interesting to hear that you've noticed the same thing.
It's very scary to publish a build. Even a quick smoke test after publishing is not enough to verify its integrity. Hopefully Unity knows about this. I tried contacting them about it a long time ago, figuring it would be sorted out later in my development, but it's been a very long time with no response. I'll look into some hacks...
I think it must be something weird about the setup, since it doesn't seem to be widespread. Are your sprites, by any chance, pretty far away from the camera and/or really large? I've found it only affects some of my sprites and maybe we have something in common there.
Also, it looks like the sprite disappears altogether if it's in a scene which isn't open in the editor at the time of building. $$anonymous$$aybe there's something broken in SpriteRenderer?
Hmm that is troubling. I definitely use $$anonymous$$ecanim to transition states for my sprite animations. However it also happens for some of my sprites that don't use $$anonymous$$ecanim as well. None of my sprites are particularly far or at crazy distances. I wonder what the root of this is...
Your answer
Follow this Question
Related Questions
2d sprite animation issue 2 Answers
How to swap sprites? 1 Answer
Animating hair over sprite animation 0 Answers
Lighting an Animated Player 0 Answers
2D sprites animation is not working - using tiled texture extended. 0 Answers