Search Unity

Mecanim issue Animator has not been initialized.

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

  1. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    I have a character exported to an assetbundle with an Animator component on it, which already has an Animator Controller attached.

    When I load my character into the game and GetComponent on the Animator, then try to set any properties on it (SetBool, SetFloat etc) I get the error "Animator has not been initialized."

    I don't see anything in the documentation and the only other reference to this error message on the forums is 3 weeks old and didn't resolve it.

    What does this message mean and how does one initialize the Animator?
     
  2. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    725
    In my short experience of the system, those are just warnings (not show-stopper errors) and usually just mean the mecanim display panel will not update in real-time when in game-mode; so you won't see all the transitions and parameters react as events occur. When this happens just deselect what you had selected and then click on the character in your scene that has the animator attached.

    Now clear the messages in the console and go into game mode. The warning messages should be gone and you should see the animator panel updating in real-time. Now why it gets "disconnected" in the first place, that I don't know...
     
  3. ph0bia

    ph0bia

    Joined:
    Sep 29, 2012
    Posts:
    6
    You need AnimatorCtrl.scripts
     
  4. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    As I mentioned in the original post I have no character in the scene, it's loaded at runtime from an assetbundle so I'm unable to do as you described. There is nothing selected in the scene prior to runtime.

    These warnings appear any time I try to set a value in the animator engine, they are definitely show stopper errors (Or indicative of another problem) as I am entirely unable to use the animation system.

    Could you elaborate? I don't see a class named AnimatorCtrl or AnimatorControl or any mention of it in the documentation.
    Edit: I found the AnimatorController class, but that's in UnityEditorInternal and doesn't appear very relevant to my issue.

    There is an animation script of course, that is the one causing these warnings
    Code (csharp):
    1. void Update()
    2.     {
    3.         if (!MyAnimator)
    4.             return;
    5.                 ...
    6.         float h = Input.GetAxis("Horizontal");
    7.         float v = Input.GetAxis("Vertical");
    8.         float r = Input.GetAxis("Rotate");
    9.         MyAnimator.SetFloat("Strafe", h, DirectionDampTime, Time.deltaTime);
    10.         MyAnimator.SetFloat("Movement", v, DirectionDampTime, Time.deltaTime);
    11.         MyAnimator.SetFloat("Rotate", r, DirectionDampTime, Time.deltaTime);   
    12.                 ...
    13.     }
    Each time SetFloat is called a warning is printed to the console saying the Animator has not been initialized.
     
    Last edited: Nov 20, 2012
  5. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    Can't seem to work around this issue, any Unity developers have some input here?

    Character works fine in a test prior to export, but once it's loaded from an assetbundle it stays stuck in T pose and won't animate at all, everything in the inspector looks identical.
     
  6. little_fish

    little_fish

    Joined:
    Nov 22, 2012
    Posts:
    1
    I have had the same problem. Do you solve the problem?
     
  7. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    Nope, we've tried multiple configurations of script/character controller/animator and still no luck, Mecanim seems to be unusable with asset bundles at this point.

    It seems like a nice system but it's far too opaque and there's a huge lack of documentation.
     
  8. mikezenox

    mikezenox

    Joined:
    Oct 18, 2012
    Posts:
    55
    Following the tutorial at http://video.unity3d.com/video/6428539/unity-4-using-mecanim I have the exact same issue. It didn't happen until I tried to restart Unity and now I can't access anything related to my Animator component. My code and scene match the video's 100% but no matter what I try they are just inaccessible. Pretty bummed out about this considering the amount of time I spent trying to narrow down my mistake just to find out there's nothing I can apparently do about it. A Unity Developer shining some light on the subject would be highly appreciated.
     
    Last edited: Nov 23, 2012
  9. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    This probably is a bug, I myself lost lots of time trying to workaround it, did you file bug report already?
     
  10. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    Hi Patrick,

    can you submit a bug with your assetbundle also reply to this thread with your case number so we can track it down more easily.

    Usually when you get a 'Animator has not been initialized.' it either if
    1. you don't have an Avatar attached to your Game Object. you can call Animator.avatar to see if it not null.
    2. you don have an Avatar but it not valid. you can call Animator.avatar.isValid to see if it valid.
    3. the controller is not valid, in that case we will need the assetbundle to find out why.

    Sonny
     
  11. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    The bug has been reported, and the case number is 502380.

    Avatar is not null, and isValid returns true.

    As for the possibility of the controller not being valid I'll await your input, but the controller in the asset bundle works fine in the test scene it was exported from.
     
  12. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    Hi Patrick,

    We got some issue with asset bundle and mecanim controller, object are not correctly bundled. There is nothing you can do right now until it fix. We will try to fix this ASAP.

    Sonny
     
  13. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    Hi Sonny,

    Any chance we can get a rough ETA on this?

    I need to know if we should wait for a fix or go back to the legacy animation system for the time being.

    Thanks
     
  14. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    No ETA at the moment but it is high in our priority
     
  15. greay

    greay

    Joined:
    Mar 23, 2011
    Posts:
    69
    Is there a workaround for this? I'm starting to try switch over from using temp sprites to mecanim, and... well, I'm getting this warning. Pretty much dead in the water.

    I am *not* using an asset bundle
     
    Last edited: Dec 9, 2012
  16. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    If not using an asset bundle everything works fine here.

    The problem only appears for us if we try to load the character at runtime from an assetbundle.

    Calling Resources.Load() on a prefab with the character that is already contained within the client works perfectly.
     
  17. patrickt

    patrickt

    Joined:
    Mar 23, 2011
    Posts:
    21
    Any updates on this?
     
  18. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    The only thing I can tell you is asset bundle is really high in our priority list.
     
  19. mikezenox

    mikezenox

    Joined:
    Oct 18, 2012
    Posts:
    55
    still nothing? I would really appreciate this being resolved.
     
  20. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,668
    This is fixed in 4.1
     
  21. panta

    panta

    Joined:
    Aug 10, 2012
    Posts:
    71
    I was having this exact problem. Make sure the animation you're trying to retarget's FBX import settings in Rig are set to Humanoid, not Generic. That fixed it for me, and I haven't updated to 4.1 yet.
     
  22. s6-pcarlos

    s6-pcarlos

    Joined:
    Feb 27, 2013
    Posts:
    3
    Version 4.1 or 4.0.1? There is no version 4.1 yet. If 4.0.1, then I am still experiencing the issue.
     
  23. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    725
    The way I understand it is: the problem is already addressed in version 4.1 (NOT 4.0.1). But we don't know the release date of that version yet.
     
  24. tedlin01

    tedlin01

    Joined:
    Mar 7, 2013
    Posts:
    23
    I need a workaround for this or an ETA for 4.1, badly.. Big company depending on this..
     
  25. tedlin01

    tedlin01

    Joined:
    Mar 7, 2013
    Posts:
    23
    Alright, in our case we found a solution..

    We have only one 3 CharacterControllers for 100 characters. We we did was to keep the CharacterControllers in the Resources folder of the Project and then just save all the characters as individual bundles.

    Once loading the characters we would get that awful message "Animator has not been initialized".

    SOLUTION: Reinitialize the controller stored in the Resources folder and reattach it to the Animator.

    CODE:
    UnityEngine.Object newController = Resources.Load("AvatarAnimator");
    System.Type engineAnimatorController = newController.GetType();
    engineAnimatorController.InvokeMember("SetAnimatorController", System.Reflection.BindingFlags.InvokeMethod,System.Type.DefaultBinder,"",new object[] { gameObject.GetComponent<Animator>() , newController } );
     
    Last edited: Mar 8, 2013
  26. Seith

    Seith

    Joined:
    Nov 3, 2012
    Posts:
    725
    In terms of an ETA for 4.1 it wouldn't be surprising if they chose to release it at GDC, which is at the end of the month. Of course, we can always hope for sooner... :)
     
  27. BatmanTheBlind

    BatmanTheBlind

    Joined:
    Mar 12, 2013
    Posts:
    9
    I have the same problem.
    For your information, Unity 4.1 has been released today !

    I hope the update will solve the problem for all of us.

    EDIT : YES ! Problem solved ! Thanks to the new class RuntimeAnimatorController !

    Here is a short sample :

    Code (csharp):
    1.  
    2. Animator currentanimator = character.GetComponent<Animator>();
    3. RuntimeAnimatorController runtimeAnimController = (RuntimeAnimatorController)Resources.Load("MyAnimatorController");
    4. currentanimator.runtimeAnimatorController = runtimeAnimController;
    5.  
     
    Last edited: Mar 20, 2013
  28. RyuMaster

    RyuMaster

    Joined:
    Sep 13, 2010
    Posts:
    468
    Don't mind this, need to do more testing, maybe my error...
     
    Last edited: Mar 16, 2013
  29. Lypheus

    Lypheus

    Joined:
    Apr 16, 2010
    Posts:
    664
    Anyone running into this of late, one additional possibility is that you are using a prefab instead of game object instance - that's what my problem was just now :).
     
  30. KelNishi

    KelNishi

    Joined:
    Dec 31, 2012
    Posts:
    6
    I'm seeing this in 4.1.3. Am I just royally screwed at this point?
     
  31. littlemuggo

    littlemuggo

    Joined:
    Apr 29, 2009
    Posts:
    13
    Seeing this in 4.2 when instantiating the prefab.
     
  32. EddieChristian

    EddieChristian

    Joined:
    Oct 9, 2012
    Posts:
    688
    This bug is still in the current build
     
  33. KayLeocore

    KayLeocore

    Joined:
    Aug 11, 2013
    Posts:
    1
    I got the same problem and I tried to figure out the solution. After a couple of minutes I realized that I was using the animator of a prefab instead of the one that is on the instance that I use in the game. That fixed it.
     
  34. Mark McDonagh

    Mark McDonagh

    Joined:
    Aug 12, 2013
    Posts:
    3
    I can confirm this is still in 4.2. In our case it seems to lead to an access violation in the C++ code that causes the Unity Editor to crash.
     
  35. Deleted User

    Deleted User

    Guest

    I can confirm also, spent the last couple of days getting around the issue. Sounds silly (Maybe) but when I used a 2/ 3 layer split screen and made Animator active it started working, what I mean by that is if Animator is running in the background it doesn't seem to do anything and flags Animator not initialized and has issues with parameters from StringToHash not being called.. Restarted Unity and it stopped working again.

    Resetting Animator after every code update seems to help as well.
     
    Last edited by a moderator: Sep 14, 2013
  36. kanga

    kanga

    Joined:
    Mar 22, 2010
    Posts:
    225
    Unity 4.2.0f4

    I am having this issue while following the excellent Stealth tutorial. If I follow the tutorial the Ethan char works perfectly with the newly created controller. My character does not. In it's own scene if I follow the steps I get the 'Animator has not been initialized; error. I have no script on my char, but the Ethan char has no script either (at least not at the stage we are up to there is no script attached to him). My custom animation has been rigged and has humanoid class, it plays in the preview fine but will not play in the game scene.

    Is there something extra in the stealth project that allows Ethan to work and my model not?
    Cheers

    Edit: My character works just fine in the Stealth scene. Player controller used for Ethan applied to my character produces no error and plays the animation loop perfectly in Game mode. Hmmm something in my new custom scene I am missing?
     
    Last edited: Sep 26, 2013
  37. attar033

    attar033

    Joined:
    Nov 21, 2012
    Posts:
    9
    I had this issue but managed to fix it. Not sure if this works for everyone but here is what I did.

    I had a generic animation that was working well until I decided to edit the uvs of the object. After importing the updated model this warning popped up and prevented the fsm from working at all. To fix this I set the Root Node in the rig import settings to a different value, applied the changes and changed it again to the value I needed (i.e "none"). The warning disappeared and everything worked fine
     
  38. sc3

    sc3

    Joined:
    Nov 2, 2010
    Posts:
    103
    I was having this error too but realised it was occurring when the GameObject that I was trying to use anim.SetBool on was inactive.
     
  39. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,418
    Yep, I'm getting the same issue if you set an animation variable on the same frame an object is enabled or disabled. This is a Unity bug IMO as when I set the animation variable both the Animator and the script setting the variable are active.
     
  40. xandeck

    xandeck

    Joined:
    Apr 2, 2009
    Posts:
    563
    Anyone still having this?
    I am getting this error from version 4.5.1 to 4.5.2, without changing anything on my code --'

    EDIT: ok, this is really ridiculous... it was just Unity update that caused this error, now I am sure... and there is more... even setting layers are not done correctly, I need to use "Invoke" to start something after I created / enabled an object...
     
    Last edited: Jul 18, 2014
  41. TSRajesh

    TSRajesh

    Joined:
    Jun 19, 2013
    Posts:
    30
    Still facing this issue... with 4.5.2.. Without changing any code..
    Looks like this is a bug that has been bugging Unity for a LONG time.. Right now my only reliable option seems to be to Not use Mecanim..
    Edit:
    Just fixed it.. Feeling like a complete idiot.. as the solution was right there in front of my face, and i had given up few versions ago.. And now suddenly it is upon me..
    When we refer to the gameobject (animator component of which we want to access) via a public variable, and we assign the gameobject in the inspector thru the selector (that tiny circle next to it), Need to make sure we select from the "scene" tab, not from the "Assets" tab. Naturally, a prefab doesn't have it's animator component initialized..
     
    Last edited: Aug 9, 2014
    Luchen likes this.
  42. Drannach

    Drannach

    Joined:
    Apr 6, 2014
    Posts:
    22
    It seems the bug is still here, i tryed the fixes above but noone worked. (unity 4.5.2).
    The amazing thing is that it says the animator has not been inizialized, but on my character the idle animation is playing and if i manually change the speed parameter inside the animator the transition works and the aniomation changes.
    I know this thread is a bit old but the problem seems not
     
  43. _dns_

    _dns_

    Joined:
    Sep 6, 2013
    Posts:
    10
    In case it helps someone !
    Just had this "animator has not been initialized" message on UI with 4.6 but it was my mistake:
    I was calling "SetTrigger" on a animator component part of a disabled gameobject ! Some other part of the code was enabeling it on the same frame, but after the SetTrigger. Placing a gameObject.SetEnable( true ) just before the SetTrigger removes the message and makes the UI animation play while being enabled/shown at the same frame.
     
  44. antx

    antx

    Joined:
    Feb 16, 2012
    Posts:
    28
    Thx _dns_ that helped me indeed.
     
  45. zero_null

    zero_null

    Joined:
    Mar 11, 2014
    Posts:
    159
    Still Facing issue in Unity 4.6.1f1 :(
    Please help
     
  46. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,114
    bump! I'm facing this issue as well in 4.6.2f1.

     
  47. super-cypher

    super-cypher

    Joined:
    May 10, 2014
    Posts:
    113
    same here!!!
     
  48. kasulogamestudio

    kasulogamestudio

    Joined:
    Mar 22, 2012
    Posts:
    130
    Just to let you know, we had this errors before. Looks like this happens if you do try to call any animation events (or variables) with a non-activated Animator component, for example, inside a non-activated game object with the Animator component. This will sure trigger this warning. But also, I really think Unity could handle this automatically under the hood, it could save us a work for checking this manually.
     
  49. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,418
    Yep, that is what I've found as well. Unfortunately it can happen even when trying to call any animation events in an OnEnable() function of a script. :( The only way around it is to set flags in OnEnable() and then do the animation events in Update(). It is very silly. Unity should definitely handle this under the hood.
     
    H_Addams likes this.
  50. kasulogamestudio

    kasulogamestudio

    Joined:
    Mar 22, 2012
    Posts:
    130
    Agreed =)
    Oh, this happens on Unity 4.x.x and Unity 5 as well
     
unityunity