Animation bug while disabling and re enabling.

Hello i’m using the animator component but when I disable it and re enable while the animation is playing the object stays where it was first disabled and doesn’t go back I did a little bit of research and people say this is a bug So? is there anywhere around this then?!?

I would send a image of what it looks like but Unity’s website glitching out rn ill post asap if needed.

You need to make sure you added keyframes for all of your animated properties in each animation clip, otherwise, this is a tricky solution:

  1. Create an empty state in your animator controller, its name by default is “New State”.

  2. Make sure the “Write Defaults” is on for that clip.

  3. Do this whenever you want to disable your GO:

    anim.CrossFade(“New State”, 0f);

    anim.Update(0f);

    anim.Update(0f);

    gameObject.SetActive(false);

While “anim” is your Animator.

It works on Unity 5.x
if you still have problems, try called anim.Update(0) 3 times or more.

This may be a bug. But you might be able to avoid it by instead of disabling and enabling the component, stopping and starting the animation in the component.

https://docs.unity3d.com/ScriptReference/Animation.html

Animation.Play and

Animation.Stop

I have the same bug, unfortunately. Although, it has some randomness because I wasn’t able to reproduce it in a smaller test scene with two cubes.

Generally, more complex stuff doesn’t like being activated or deactivated in Unity. This is just another bug in the long list.

I’ve found a potencial solution which can be found here: restoring hierarchy transform original state before deactivating animator