- Home /
Losing Animator state on Disable/Re-enable?
Hi i am making a FPS game and have a simple WeaponManager script that disables & re-enables weapons, but each weapon has its own Animator compoment and whener i disable and then re-enable the gameObject(weapon) then it messes with my Animations. Is there any solution for this please? im starting to think that i should completely abandon Unity
What do you mean by messes? Anyway you can just play the animation you need once you are activating the gameObject.
For example:
gameObjectAnimator.Play("your_animation_name", -1, 0f);
'your_animation_name' is your animation which should play
'-1' is the layer, -1 means default (first)
'0f' is start time of the animation
Sir this doesnt work, by " messes" i mean that if the gameObject has been disabled then Re-enabled, the animations doesnt play the way it should as when i start the scene
Hm, it's strange. It should work. I know this problem, you can start the game and manually in the editor disable/re-enable the gameObject with the Animator and you will see the broken animation flow.
Easy fix is just restore the all states, triggers, bools and other in the Animator. So, once you are activating the gameObject (like gameObject.SetActive(true)) you need to restore the all previous states (Play the animation, SetBool, SetTrigger (if any)).
It should work, looks like you are doing something wrong there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612165136im_/https://answers.unity.com/themes/thub/images/avi.jpg)