Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Animator has not been initialized - b20

Discussion in 'Unity 5 Pre-order Beta' started by grosssmutttr, Jan 18, 2015.

  1. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    168
    Hi there,

    just updated our project to the new beta 20 (previous version 18)

    Now when I SetTrigger("something") I'm getting this error:
    Animator has not been initialized.
    UnityEngine.Animator:SetTrigger(String)
    ItemFollowChangeManager:OnMouseDown() (at Assets/Scripts/ItemActions/ItemFollowChangeManager.cs:316)
    UnityEngine.SendMouseEvents:DoSendMouseEvents(Int32, Int32)

    This is what I'm doing in the script:
    gameObject.GetComponent<Animator>().applyRootMotion=false;
    gameObject.GetComponent<Animator>().SetTrigger("putzen");

    Any ideas or a workaround?
     
  2. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    168
    If I run the game and manually set the applyRootMotion to false it works as before in beta 18...
     
  3. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Check first that you have a correct Animation Controller assigned and no relationships or components are broken.

    Next, you've got to stop the lazy practise of going gameObject.GetComponent<Blah>().whatever; because it's a recipe for disaster.

    Code (CSharp):
    1. Blah b = gameObject.GetComponent<Blah>();
    2. if (b != null)
    3. {
    4.        do stuff
    5. }
    6. else
    7. {
    8.      Debug.LogWarning("null");
    9. }
    Something like this will let you know if you're even finding the right component, and lead to much better stability.
     
  4. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    168
    Tested this:
    Animator a = GetComponent<Animator>();
    if(a!=null){
    a.applyRootMotion=false;
    a.SetTrigger("putzen");
    }

    Same alert is showing.

    It worked in beta 18 so perhaps this is a bug?
     
  5. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    Please feel free to report it, although we do this often and have no bugs (b20). It could be you have a niche case.
     
  6. grosssmutttr

    grosssmutttr

    Joined:
    Apr 15, 2014
    Posts:
    168
    Do you also set applyRootMotion?
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
  8. graham20

    graham20

    Joined:
    Sep 28, 2013
    Posts:
    3
    Did you report this issue? I'm getting the same problem in release candidate one. It only happens when I switch applyRootMotion to false in code and then try to set an animator value.

    All of my other animations work fine and I didn't have any issues in Unity 4.
     
  9. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    It needs reporting or it probably won't get fixed for several hundred thousand decades.
     
  10. graham20

    graham20

    Joined:
    Sep 28, 2013
    Posts:
    3