Animator is not playing an animatorcontroller ошибка

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?

asked Mar 9, 2018 at 21:38

Basile Perrenoud's user avatar

Basile PerrenoudBasile Perrenoud

4,0313 gold badges29 silver badges52 bronze badges

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);

answered Mar 9, 2018 at 21:38

Basile Perrenoud's user avatar

Basile PerrenoudBasile Perrenoud

4,0313 gold badges29 silver badges52 bronze badges

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

answered Mar 9, 2018 at 23:26

JeanLuc's user avatar

This warning also occurs, when you try to run methods on an Animator (SetFloat/Play/etc.) that is attached to a Prefab, instead of a instantiated GameObject.

For example:

You have a GameObject (name — «MyLists») with List type Duck.

Duck is just a regular prefab with a script that has a method , let’s say.. «ShowUp()» .

The list fullfills with Duck GameObjects by itself. Doesn’t matter how.

Your other GameObject (name — «Manager») on a scene runs method «ShowUp()» on every Duck GameObject in the list. But because of some reason, you want to run method «ShowUp()» even if there are no object (no Ducks) on the list. Because this method makes some cool stuffs. So you assign the Duck Prefab to the Manager GameObject, so it can take a script from this Duck prefab, and run method «ShowUp()». If the method «ShowUp()» has something like «animator.SetFloat(…)», it will cause an warning we’re talking about.

*It will not cause an error «animator not assigned», because Duck prefab may have assigned «animator» in the Inspector.

Next part of this post is about a real «Duck» problem that I’ve had

You don’t need to read it if you’re not interested, you already know everything that you need about error/warning we’re talking about.

You can say.. Well, that’s weird thing won’t ever happen, why should I run «ShowUp()» when there are no Ducks. But that’s not true. Look at this:

I make a multiplayer game with object pooling. Only the Master Client (or server) can add new objects to the pool. After that he send message to everyone that he has just created a new object in the pool, and everyone needs to that in theirs local pools too (to stay synchronized). Of course, all this time the Master Client sends data about every object in the pool to other players, so they can be synchronized (like position, velocity, etc.). Every data he sends MUST be read by a client. If that won’t happen client may read «old» data as a new message, and assing values (like position, velocity) to a different object in the pool. In case Master Client adds new object to the pool, he starts to send data about it to everyone. Sometimes client won’t catch up to make this new object before he gets informations about it. So he need to make something like «fake read», just read informations but do not assign them to any gameobject (because he didn’t create the proper one). That is when I want to use Read method from a prefab, I just set a parameter fakeRead to True in method Read(bool fakeRead) and it does a fake read. If in my Read method I use animator.SetFloat((float) stream.ReceiveNext()) it will cause an warning we’re talking about, because an animator is a prefab’s animator.

Let’s say the Master Client has just created third object, and he now sends informations about objects.

for every object: object.SendsInfo() (it will runs 3x times)

Client didn’t create object3 yet, but he receives data:

for every object: object.Update(stream.ReceiveNextData()) (it will runs 2x times)

in next loop Client will subscrive informations about object3 to object1 !!!

Of course I propably can walk around this problem in a different way, maybe like flushing streams, change the way master communicates with client, etc. But hey! that’s my solution for now and it works perfect! :)

I’ve just started adding tests to my game project in Unity. I know the difference between EditMode and PlayMode tests. I’ve written a PlayMode test that triggers a change to the Animator internally, but this fails as the parameter in the Animator doesn’t seem to be changing. I also get the warning Animator is not playing an AnimatorController everytime I call GetFloat or SetFloat, which I suspect is an indicator of my issue.

Script under test

public class ChangeDirection : MonoBehaviour
{
    public Animator animator;

    public void SetDirection(Direction direction)
    {
        var directionVector = new Vector2(0f, 0f);

        switch (direction)
        {
            case Direction.Up:
                directionVector = Vector2.up;
                break;

            case Direction.Down:
                directionVector = Vector2.down;
                break;

            case Direction.Left:
                directionVector = Vector2.left;
                break;

            case Direction.Right:
                directionVector = Vector2.right;
                break;
        }

        animator.SetFloat("Horizontal", directionVector.x);
        animator.SetFloat("Vertical", directionVector.y);
    }
}

PlayMode test

public class ChangeDirectionTests
{
    [UnityTest]
    public IEnumerator SetDirection_DirectionUp_VerticalChanged()
    {
        var gameObject = new GameObject();
        var animator = gameObject.AddComponent<Animator>();

        animator.SetFloat("Horizontal", 0f);
        animator.SetFloat("Vertical", 0f);

        var changeDirection = new ChangeDirection();
        changeDirection.animator = animator;
        changeDirection.SetDirection(Direction.Up);

        Assert.AreEqual(0f, animator.GetFloat("Horizontal"));
        Assert.AreEqual(1f, animator.GetFloat("Vertical"));
    }
}

Test output

SetDirection_DirectionUp_VerticalChanged (0.017s)
---
Expected: 1.0f
  But was:  0.0f
---
at ChangeDirectionTests.SetDirection_DirectionUp_VerticalChanged () [0x00063] in /home/samuelslade/source/games/pokemon-world/Assets/Tests/EditMode/ChangeDirectionTests.cs:22
---
Animator is not playing an AnimatorController
Animator is not playing an AnimatorController
You are trying to create a MonoBehaviour using the 'new' keyword.  This is not allowed.  MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
Animator is not playing an AnimatorController
Animator is not playing an AnimatorController
Animator is not playing an AnimatorController
Animator is not playing an AnimatorController

The warning around using the new keyword to create a MonoBehaviour has this further detail:

You are trying to create a MonoBehaviour using the 'new' keyword.  This is not allowed.  MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at all
UnityEngine.MonoBehaviour:.ctor ()
ChangeDirection:.ctor ()
ChangeDirectionTests/<SetDirection_DirectionUp_VerticalChanged>d__0:MoveNext () (at Assets/Tests/PlayMode/ChangeDirectionTests.cs:17)
UnityEngine.SetupCoroutine:InvokeMoveNext (System.Collections.IEnumerator,intptr)

I’m clearly misunderstanding how this works, so any direction to help me understand how best to approach writing tests in Unity would be appreciated.

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Pick a username
Email Address
Password

By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.

Already on GitHub?
Sign in
to your account

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 doesnt 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);

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

c# – Animator is not playing an animation controller

Понравилась статья? Поделить с друзьями:

Не пропустите эти материалы по теме:

  • Яндекс еда ошибка привязки карты
  • Android adb interface ошибка код 10
  • And тонометры ошибка err cuf
  • And ub 201 ошибка
  • And ua777 ошибки тонометр

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии