- Home /
How to reset the animation after a gameobject is deactivated in Unity?
I have a simple cube gameobject which has an animator component attached to it. This animator only controls one simple animation clip, this animation clip simply changes the scale of the gameobject from (1,1,1) to (2,2,2) in half a second.
Now in an another script lets say GameManager I trigger this animation by anim.SetTrigger("Scaleup")
and thats works fine where the cube gameobject scales to the correct values which is (2,2,2).
All i'm after here is: When this cube gets deactivated and then reactivated again the animator does reset to its default state (Idle state) but the size never gets back to its original scale which is (1,1,1) and stays at (2,2,2) no matter what I do which it seems impossible in unity.
How can I reset the values of the animation clip when a gameobject gets deactivated and reactivated again?
I tried doing this anim.enabled = false
and anim.enabled = true
but it doesn't work. Help Guys.
Answer by SeahorsePro · Jan 19, 2020 at 10:08 PM
After the cube is enabled again what is the scale in the inspector? Could you not simply scale it via script, something like:
transform.localScale = new Vector3(1, 1, 1);
I don't know what your code is so I don't know where to implement it but if you share it that would give more insight.