Animator does not reset well when reactivating object

Hello, everyone!

I have a 2D cutout-animated GameObject with 3 animation states: Idle (loop), Interact (non-loop) and Leaving (non-loop). When the user clicks on the object, a trigger is sent to start the Interact animation, and it transitions to the Leaving animation via Exit Time.
I also have another trigger, called Idle, which resets the animation to the Idle state.

It all works fine… until I deactivate the GameObject while it is on the Leaving state. By reactivating it, the animator is back on the Idle state, but many parts of the object are on weird positions, and some sprites are wrong. It seems all the changes made by the last animation Leaving which are not “undone” by the Idle animation stay there.

If it was supposed to work like this by design, how come transitioning through the whole cycle while the object is active works fine?
Any ways to fix this?

Thank you!

What worked for me was to make an animation with all default values, and then play it before deactivating the object. I think is kind of easy, but let me know if you need more specific details.

Hi @marconi. I’m having exactly the same issue. Please, can you tell us if you finally solved it?

Maybe this tip is too obvious, but it wasn’t for me at the time so I will share it.

Since you need that the DEFAULT animation has the same KEYFRAMES of the animation that was playing when it was disabled, What you can do is COPY the keyframes of that last animation, and PASTE them on the FAR end of the DEFAULT animation there you will clearly see the missing keyframes that you need.

Double click at the START and END of the TIMELINE to add that KEYFRAMES that you are missing, DELETE the KEYFRAMES you PASTED and you are good to go.

Using this solved the problem for me:

animator.keepAnimatorControllerStateOnDisable = true;