3
votes

My animator doesn't work: I set a bool variable from code:

animatedObject.myAnimator.SetBool("MyVariable", true);
animatedObject.SetActive(true);

But the animation isn't triggered. I'm sure that the animator's transition is correctly set to react with "MyVariable".

Looking at the output console, I see that I have a warning:

animator is not playing an animation controller

What does that mean?

2

2 Answers

3
votes

The warning is not really helpful but what it means is that the AnimationController is disabled, or is on an inactive object. It will not be able to set variable since it currently doesn't have a state.

Simply inverting the two lines, so that the animator is on an active object, will solve it:

animatedObject.SetActive(true);
animatedObject.myAnimator.SetBool("MyVariable", true);
2
votes

The warning Animator is not playing an AnimatorController also appears, when the Animator somehow lost the reference to the Animator Controller asset.

You can see it here in screenshot, where the Animator value for Controller is "None". Just drag in the missing Animator Controller asset from your project view.

Missing Animator Controller