Animator has not been initialized - b20

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:smile:oSendMouseEvents(Int32, Int32)

This is what I’m doing in the script:
gameObject.GetComponent().applyRootMotion=false;
gameObject.GetComponent().SetTrigger(“putzen”);

Any ideas or a workaround?

If I run the game and manually set the applyRootMotion to false it works as before in beta 18…

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().whatever; because it’s a recipe for disaster.

Blah b = gameObject.GetComponent<Blah>();
if (b != null)
{
       do stuff
}
else
{
     Debug.LogWarning("null");
}

Something like this will let you know if you’re even finding the right component, and lead to much better stability.

Tested this:
Animator a = GetComponent();
if(a!=null){
a.applyRootMotion=false;
a.SetTrigger(“putzen”);
}

Same alert is showing.

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

Please feel free to report it, although we do this often and have no bugs (b20). It could be you have a niche case.

Do you also set applyRootMotion?

Nope.

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.

It needs reporting or it probably won’t get fixed for several hundred thousand decades.

I raised the bug and it got confirmed then raised as a duplicate of this:

@grosssmutttr Please vote on the issue if it’s still causing you problems :slight_smile: