Can't play animation after setting GameObject to inactive and back to active again

I have an UI element which has an Animator component attached with a simple looping animation that fades it in and out.

This UI element needs to be turned on or off on multiple occasions, so I have a script that disables it as needed using SetActive(false).

However, though it animates correctly at the start of the game, as soon as I’ve set this to SetActive(false) and then SetActive(true) again, or if any of its parent GameObjects go through the same process, the looping animation stops and I cannot figure out how to make it start playing again.

I’ve tried manually playing the state with .Play(“statename”), as well as manually turning the actual Animator component on and off again with no luck. This is an extremely simple application, so I was hoping I’m missing something obvious here…

Edit: As mentioned in the comment chain of the original post, it turns out that the cause is the UI window setting Time.timeScale to 0 to pause the game while open, which naturally also pauses the animation. Can this be overridden or circumvented somehow? I’ll need to use these kind of UI animations while the game is paused, and setting the timeScale to 0 seems like the most reliable way to do this.

You probably solved it by now, but in the inspector you can change to Unscaled Time the animator update, this way it will not be influenced by the game timescale.

Try to enable and disable self animator on object.

link text

Add the overcondition and try it

Setting this as resolved since the issue is separate from the original question. Thanks to @xxmariofer for suggestions!

you shoude use this:
if (isActiveAndEnabled) {
animator.CrossFade(acname, 0f, -1);