Categories
Development Unity

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.

Leave a Reply

Your email address will not be published. Required fields are marked *