Animation resetting variables when finishing

I’ve spent hours trying to debug this animation but I’ve had no success. All I’m trying to do is have an animation disable a gameobject with a keyframe, then have that object stay disabled even after the animation ends.

I must be missing some obvious, fundamental animation info because I’ve looked all around the internet and found no one with this issue.

This is a simple animator that goes from Idle → Animation that hides the gameobject → A second idle state. Each transition is exactly the same:
- Has Exit Time: True
- Exit Time: 1
- Fixed Duration: True
- Transition Duration: 0
- Transition Offset: 0
Additionally, there are no conditions between the 3 states, so it’s basically just cycling over and over.

What happens during gameplay is it spends 1 second in Idle, transitions to PlayerTabHide, which successfully disables the GameObject about 0.8 seconds in, then immediately re-enabled the GameObject when transitioning to Idle2

This is the PlayerTabHide animation. The first keyframe enables the gameobject, the second keyframe disables it, and the third keyframe at the end also disables it.

The GameObject being enabled/disabled is just a UI image on the screen.

What I’ve done for debugging:
- I am running Unity 2020.3.33f1
- I do not have any other script/animation affecting the GameObject
- I have tried WriteDefaults both on and off
- I’ve tried all the Clamp Modes for the animation
- I’ve tried lots of different animation transitions combinations
- I’ve tried 1 keyframe, 2 keyframes, keyframes only at the end, only the beginning, etc
- The animation is not being affected by the Animation Tab Preview
- Animator.keepAnimatorControllerStateOnDisable has no effect

If anyone knows what’s wrong PLEASE help me. Whenever I try to enable/disable GameObjects with Animations it causes a complete breakdown. I akways have to enable the gameobject at the beginning of the animation before I can disable it, which doesn’t seem correct to me.

2 Likes

I have the same problem. All I know is that it worked with serialization version 3 Animators but the newest version 2020.3.43 forces a migration to serialization version 5 which produces exactly the behavior you describe. I am not sure if it is some sort of regression or an intentional change to the api but thinking back to when I implemented this stuff the only thing I can recommend is to NOT TOUCH the unity animator system if you intend to use it through scripts in any way. It exposes ways of using it this way but it doesn’t seem like it was ever designed to be used this way. It was broken back then and I am honestly not surprised it got even more messed up since then.
The entire system is very fragile and full of non-deterministic variations based on the framerate.