- Home /
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.
Are you calling Rebind() function? $$anonymous$$aybe this will help: https://forum.unity.com/threads/losing-animator-state.307667/#post-3598984
Answer by OUSS23 · Aug 10, 2018 at 10:45 AM
You need to make sure you added keyframes for all of your animated properties in each animation clip, otherwise, this is a tricky solution:
Create an empty state in your animator controller, its name by default is "New State".
Make sure the "Write Defaults" is on for that clip.
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 works well! Thank you so much! Btw, in my case it worked in the OnEnable-method. And only with one call of anim.Update(0f); (Unity Version 2020.1.2f1)
Answer by Dudicus · Jul 16, 2017 at 12:02 AM
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
Sorry if this confused you I didn't mean to say animation meant to say mechanim animator. Or unless mechanim has animation.play and stop
I have the exact same bug. Sadly I can't just stop the animation, because my GameObject has to disappear from the screen (and the Animator component aswell). When it come back enabled, the default state of the animation is never reached on screen, even though in the Animator window shows like the animation is on the "correct state". This just happens if the Animator disappear when the animation is been played in a state different than the "inicial default" state. I don't know if helps, but this bug SEE$$anonymous$$S to occur also when animate a transition between two states where "Write Default" is disabled. I just don't know what to do to solve this and this bug (if this is really a bug, not something that I'm missing) is delaying my progress on my project.
Answer by ProgOrion · Jul 18, 2017 at 11:31 PM
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.
Oh, just mentioning, that the legacy Animation component doesn't have this bug. There you can freely disable and/or enable animations.
Have the same bug. Found a workaround to call Rebind() in a LateUpdate() https://forum.unity.com/threads/losing-animator-state.307667/#post-3598984
Thanks for mentioning, maybe it will be useful to me later on!
Answer by lorux · Sep 05, 2019 at 02:19 PM
I've found a potencial solution which can be found here: restoring hierarchy transform original state before deactivating animator
Your answer
Follow this Question
Related Questions
Animation load bug 0 Answers
Animation doesn't play but controller works correctly (Legacy issues) 0 Answers
Unity 4.5.2 bug changing the properties of the 2d colliders in animation 1 Answer
Scene loading time after upgrade from 5.5 to 5.6 4 Answers
i get weird rotations on my animated objects using legacy, help? 0 Answers