GameObject Transform values incorrect when disabled mid-animation
Hi,
I have a GameObject with an Animator and Animation component. I made a simple MechAnim state machine with an idle (which does nothing) and one animation that tweens the local scale X value to make the object shrink and then expand (non-looping.) In the app, the object can get a SetActive(false) called on it at any point, and when this happens in the middle of the animation, the object's local scale stays at whatever it was when the object was disabled when it is re-enabled later. So, if the object's scale was [0.5, 1, 1] when it was set as inactive, when I set it active again, the object's scale is stuck at [0.5, 1, 1] instead of returning to [1, 1, 1].
I've tried using Animator.Rewind() on the GameObject both in OnDisable() and OnEnable(). I've also tried recording the original scale values OnAwake() and then forcibly resetting the object's local scale values in the first LateUpdate() after the object is set active again. None of these solutions work. The object goes right back to the [0.5, 1, 1] state even after I try to reset all animations and restore the transform values.
I could use some help figuring out how to smoothly handle interrupting animations that modify the GameObject's transform values when I call SetActive() on the GameObject.
Answer by tormentoarmagedoom · Jul 04, 2018 at 05:17 PM
Good day.
I dont know the solution for the animation. But why dont just destroy the object and instantiate it again, instead of deactivating it?
Bye!
Hi,
Well, the object is just meant to be hidden temporarily, so I want to be able to hide it and bring it back so it keeps all of its internal states. I could try not rendering it, but I also have some collision volumes with triggers on them for it to animate & play sound. I don't want the triggers firing off while the object isn't being rendered, and I don't really want to walk all of the components on it and all its child GameObjects and disable them all individually just to get around this. It would be nice if the Animation system would just restore the changes it was making to the transform values and reset itself if it gets interrupted.
Thanks!