Why when you disable then re-enable the same game object the animation is restarted?

Hello,

I create a simple project and the put one animated (Unity Animation) cube If I disable the Cube the animation is paused in the Animator but If i re-enable the GameObject the animation restart from the beginning.

I want to pause the current animation & hide the gameobject then resume the same animation.

Thanks.

Donwload the unitypackage:
https://dl.dropboxusercontent.com/u/34379764/Animation_restart.unitypackage

Yes, when you disable an Animation component, it releases its memory. When it gets re-enabled, it restarts everything. You’ll have to save the state on your own and then resume that state right after re-enabling the Animator.

2 Likes

I find this behavior counter-intuitive. If I wanted to release the memory I would delete the game object. How should one disable object temporarily without some hacks?

Mecanim.Dev wrote more about it in this post and this post. In the second link, another user posted a wrapper script that helps address this.

Thanks for the links. So I’m not the only one :slight_smile: But it looks like they’re going to support “persistent” state in the future.

You could also just disable the mesh renderer component on the cube game object without disabling the entire cube. ( I think). Basically the cube keeps spinning, but is now invisible.