- Home /
Animation stops playing after disabling and enabling game object
Basically, the short version is that I call gameObject.SetActive(false) on a game object when I pause the game and then gameObject.SetActive(true) when resuming. For some reason this stops all animations on the game object. I am not calling animation.Stop(), or any other animation functions. I tried debugging and the isPlaying flag on the Animation component is getting set to false. Animations will resume when there is any kind of input. Any ideas on why this would be happening?
EDIT: I should note that I'm calling gameObject.SetActive(true) on the parent object, and the Animation component is located on a child of that object.
Answer by Paulius-Liekis · Aug 22, 2013 at 06:59 AM
This is by design, although I don't remember why it's implemented this way.
So is there a way to continue playing the animation that was already playing, perhaps using the OnEnable() function?
I would VERY much like to know this too as it's hugely interfering with my culling system (which sets parents objects of sections of my level to Active=false). $$anonymous$$y enemies rely heavily on their animations for their behaviour, so they often break completely when re-entering a zone that was previously culled.
I'd like to know a way too as I'm currently getting the same issue on my project
Answer by sebastiansgames · Aug 02, 2016 at 12:00 PM
ah okay -- in my case this was due to the fact that my game object had a coroutine that was constantly determining the object's speed and feeding it to the animation so it knew what animation to play (i.e. run etc).
disabling the game object stopped the coroutine.
re-starting up that coroutine in OnEnable fixed this issue in my particular case.
Your answer
Follow this Question
Related Questions
Check if multiple gameObjects play animation 2 Answers
UI Animation Not Playing 1 Answer
How to check if an object is playing ANY animation 1 Answer
How to use one trigger that will set object active then when hit the 2nd time will deactivate it? 1 Answer
Animation plays without a bool, but after adding it just goes still 0 Answers