Animator has not been initialized??

I’ve been working on a Client type of UI. The buttons all have transition type Animation, with an attached animator. When buttons are disabled, they scale down. When enabled, they return to (or just are) normal scale. For some reason, when I run my function to reset everything, I sometimes get the error “Animator not Initialized” and sometimes dont, but the transition animations just stop playing. I’m 100% sure I’m not setting the animator null anywhere in the code, and I’ve tried button.interactable = true, button.animator.SetTrigger(“Normal”), and button.GetComponent().SetTrigger(“Normal”). The buttons stay scaled down (but ARE interactable again)

What’s happening?

When the GameObject containing an animator is turned on, the animator starts uninitialized, and is initialized that frame. If you attempt to call methods on the animator in the same frame it’s being initialized, the call may go through before the initialization finishes, and Unity will refuse to run the command. The transition won’t occur because you never actually set the trigger. The solution would be to wait a frame after turning on the object, and then call your method.

I believe that the initialization happens each time the GameObject is activated, not just the first time. As an alternative to waiting a frame, you could try LateUpdate or yield return new WaitForEndOfFrame().

Put it in a coroutine and wait until the animation isInitialized flag is true.

I was having this same problem and this thread helped me track it down…

I have a CanvasGroup holding my three buttons. The CanvasGroup had interactable set to “false” and alpha to zero, so the menu wouldn’t be there on load. The Buttons are using Animation transitions, and the CanvasGroup has an animator to fade the whole menu in and out.

My workaround/solution so far is to leave the CanvasGroup interactable = true, but the default animation state is one that sets it to false. The warnings are completely gone now.

Down side is, I think that there now might be some amount of time (hopefully only one frame) at load when the invisible buttons are interactable. Not sure if that will cause any problems or not.