Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Mecanim issue Animator has not been initialized.

Discussion in 'Animation' started by patrickt, Nov 16, 2012.

  1. Knarhoi

    Knarhoi

    Joined:
    Apr 11, 2015
    Posts:
    9
    I'm not sure if this is any help, but I have a character that changes controller and I'm using this code setup in Unity 5.0.0f4:

    Anim = GetComponent<Animator>();
    Anim.runtimeAnimatorController = Resources.Load("Animators/Characters/Hero_animator") as RuntimeAnimatorController;


    Please note the necessity of the resources folder.
     
  2. artaka

    artaka

    Joined:
    Feb 19, 2013
    Posts:
    128
    I'm also getting the "Animator has not been initialized" warning 999+ times when building. I'm running Unity 4.6.3p4. The console has no info where the warning originates but the Editor log has a bit more info.. Here it is:

    Animator has not been initialized.
    UnityEngine.Animator:ResetTriggerString(String)
    UnityEngine.Animator:ResetTrigger(String)
    UnityEngine.UI.Selectable:TriggerAnimation(String) (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Selectable.cs:486)
    UnityEngine.UI.Selectable:InstantClearState() (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Selectable.cs:248)
    UnityEngine.UI.Selectable:OnDisable() (at /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Selectable.cs:192)
    UnityEditor.BuildPipeline:BuildPlayerInternalNoCheck(String[], String, BuildTarget, BuildOptions, Boolean, UInt32&)
    UnityEditor.BuildPlayerWindow:BuildPlayerWithDefaultSettings(Boolean, BuildOptions, Boolean)
    UnityEditor.BuildPlayerWindow:BuildPlayerWithDefaultSettings(Boolean, BuildOptions)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()

    [/Users/builduser/buildslave/unity/build/Runtime/Animation/Animator.cpp line 2715]
    (Filename: /Users/builduser/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Selectable.cs Line: 486)
     
  3. artaka

    artaka

    Joined:
    Feb 19, 2013
    Posts:
    128
    After some digging, I found the 999+ warnings I was getting were due of all the uGUI Buttons I had in the scene whose states were being animated by an Animator component. The issue was that the Animator component on the GameObject followed the Button component. This is the default Unity setup when clicking "Auto Generate Animation" button in the inspector of Button component. Simply switching this order so that Animator component was above the Button component got rid of all the warnings.
    Hope this helps.
     
  4. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,114
    I'm getting about 100 of these when building...
     
  5. XUTERO

    XUTERO

    Joined:
    Mar 9, 2013
    Posts:
    2
    Hi everybody, I had that same issue in Unity 5.0.2f1
    I didn't change anything in my code. I did some backup of my project and animator controllers didn't seemed to work any more.

    I deleted the ones not working and replaced them with copies of my backup. Everything solved and working fine now.


    Note: In the editor, the animator controllers didn't show their normal icons. After deleting and copying from backup, their icons reappeared and everything worked again.

    I'm not using assets bundle.
     
  6. chasepettit

    chasepettit

    Joined:
    Oct 23, 2012
    Posts:
    42
    I'm still having issues related to Animators in AssetBundles in Unity 5.1.0f3. Essentially, my issue is that after you've instantiated a prefab with an Animator on it from an AssetBundle, unloading the AssetBundle causes big problems if you try to have the object persist across a LevelLoad.

    Some additional details in the bug report I submitted.
     
  7. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    Yes loading an AnimatorController from an asset bundle in 5.1 crash the editor. This issue was fixed yesterday and should make it way to 5.1 p2.
     
  8. chasepettit

    chasepettit

    Joined:
    Oct 23, 2012
    Posts:
    42
    Thanks for the info.
     
  9. davood

    davood

    Joined:
    Apr 30, 2014
    Posts:
    3
    hey this is not bug.
    you must assign (gameobject contain animator) from hierarchy, not directly from project panel.
     
  10. davood

    davood

    Joined:
    Apr 30, 2014
    Posts:
    3
    it means you must assign it after instansiate.
     
  11. TruffelsAndOranges

    TruffelsAndOranges

    Joined:
    Nov 9, 2014
    Posts:
    92
    Getting completely spammed with this in latest version (5.1.1f1). :'(

    Anyone found a solution that is really a solution and not just a hack-a-round?
     
  12. Knarhoi

    Knarhoi

    Joined:
    Apr 11, 2015
    Posts:
    9
    This worked for me. No errors. :)
     
  13. H_Addams

    H_Addams

    Joined:
    Aug 5, 2015
    Posts:
    1
    Had the same warnings for ages and couldn't figure out how to solve this until I saw Antony's post. I had the messages from Unity 4.something till 5.something. It really do occur when you set variables of the animator in the same frame you enable it (OnEnable() for example). I had to change my scripts so it set variables only the frame after it was enabled and then Bingo! No more warnings! Thanks Antony!
     
    Antony-Blackett likes this.
  14. HelloRainbow

    HelloRainbow

    Joined:
    Nov 10, 2015
    Posts:
    1
    I figure this out.
    Animator not ready in this frame. Invoke animator method in the next frame.
    Use coroutine like this :

    IEnumerator doSomething()
    {
    yield return new WaitForEndOfFrame();
    obj.GetComponent<Animator>().SetBool("walk", true);
    }
     
  15. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
  16. Albertkaruna

    Albertkaruna

    Joined:
    Apr 12, 2015
    Posts:
    9
    We had the same problem but finally we solved it. The problem was the gameobject which holds the Animator component must be active on the scene before you set the variables.
     
  17. rad1c

    rad1c

    Joined:
    Feb 26, 2016
    Posts:
    21
    confirmed in v5.3.4x1
    So in April 2016, same issue exists. 4 good years of persistence. next year we can celebrate
     
  18. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    This is not a bug, it just mean that the animator component is not yet enabled or initialized.
    It can happen if
    1. you try to call an animator function(like SetBool()) while the GameObject is disabled.
    2. you set a parameter before the animator get a chance to initialized itself.

    The best way to avoid this warning is to call Animator.Rebind() in a Monobehaviour.Start() like this
    Code (CSharp):
    1.  
    2. void Start()
    3. {
    4.     Animator animator = GetComponent<Animator>();
    5.     if(!animator.isInitialized)
    6.         animator.Rebind();
    7.            
    8.     // Now you can set parameters or call any animator's functions
    9.  
    10. }
     
    Rodolfo-Rubens likes this.
  19. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,418

    Thanks for the help. I guess it's just odd that an Animator can be in an uninitialised state when at the most common time when you'd want to trigger an animation like in Start() or OnEnable().
     
    Last edited: Feb 28, 2017
  20. rad1c

    rad1c

    Joined:
    Feb 26, 2016
    Posts:
    21
    Thanks for the reply. Smells like a workaround/hack for something should be handled internally by Mecanim (or Unity Engine itself).
    If I'm wrong here, could you please give an example for a good use and an actual reason of this feature/behaviour (i.e. use case)?
     
    Last edited: Apr 12, 2016
  21. pushxtonotdie

    pushxtonotdie

    Joined:
    Oct 21, 2010
    Posts:
    100
    I think the issue with this warning is the messaging. I had an issue where I created an animation override controller and then set some curves on a dynamic animation clip. This caused the animator to 'not be initialized' while in reality the setting of the curves meant that the animator just needed to be rebound. Since this doesn't seem to happen automatically, it may be better to change the message to 'Animator is not initialized or animation clips have unbound changes. Maybe you need to call Animator.Rebind()?'. Or something, just spitballing.
     
  22. CyberGolem

    CyberGolem

    Joined:
    May 1, 2013
    Posts:
    20
    Silly question but how are you able to do this? When I select the bullseye icon, it pops open a window to select RuntimeAnimatorController, and the only tab is for Assets. There isn't another tab available.
     
  23. CyberGolem

    CyberGolem

    Joined:
    May 1, 2013
    Posts:
    20
    Same with me; everything was fine then I attempted to remove the empty event causing the error. I must've accidentally added it at some point, but it's suddenly impossible to select animation keys or events in the animation view. This includes trying to select either by drag-marquee or individual keys on the timeline, events or even the Add Curve button. Anyway, both the dope sheet and curves editor are misbehaving. I can see the offending event and though a mouse-over invokes a hint, that's all it will do. If there's supposed to be a lock icon, it's missing.

    I'm not sure if it's a related issue, but when dragging a window to a new location, the docking indicator (panel icon thingy in the center of a docking area when rearranging panels) isn't popping up either. I can dock a panel to the side of another one but not directly on top of one.

    Unity4.6.9 :: dX11 :: Win10
     
unityunity