Effects of gameobject.setActive(false) on the animator.

tl;dr What happens to an animator when a script calls to GameObject.setActive(false) to the enclosing game object?

“Long” version:

We got this GameObject, with an Animator and a simple state machine and the controlling script. When something on the game happens, some functions and animations are called, with a final call to setActive(false) for the GameObject.

Then the GameObject is sent to a “respawn queue” where it is re-activated again after some time.

My “problem” is that, after reactivation, I need to move from “Idle despawn” to “Spawning”, but somehow, the State Machine goes back again to “Idle spawned” (The default state), so my guess is that the state machine is resetting after the setActive(false) instruction. Still, I haven’t been able to find any kind of information on this, just my spidersense tingling.

Any info on this topic? Maybe some suggestions on how to proceed with my problem?

It’s an old post but I’d like to point out there’s a property now in the animator class:

which will prevent animator from resetting state when disabled.
I’m using 2018.4 so not sure if it’s a new property or it can be found on older versions.

You are exactly correct. The state machine on any animator resets to its initial state when turned off/on.

If you need to run an animation from Idle despawn to Spawning, you could, upon enabling the animator, switch to the idle despawn state and then trigger the animation. Or, you could trigger this animation just before you disable it.

Either of those solutions could get messy though, unless you’re careful.