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

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

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.

Tezr0

0 / 0 / 0

Регистрация: 13.09.2022

Сообщений: 1

1

13.09.2022, 15:34. Показов 724. Ответов 1

Метки unity (Все метки)


Студворк — интернет-сервис помощи студентам

Привет всем читающим. Я новичок в юнити. Делаю игру битва башен. Столкнулся с проблемой «animator is not playing an AnimatorController». После призыва скелета(префаб) он идёт вперёд все спокойно, он стреляет и когда враг попадает в триггер который висит на скелете он стреляет во врага, при попадании происходит эта ошибка «animator is not playing an AnimatorController». В инспекторе все указано.

Скрипт скелета:

C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
public class Skelet_meh : MonoBehaviour
{
    public Animator animka;
 
    public Health Enemy_Health;
 
    public Rigidbody2D rb;
 
    public GameObject Castle_Red;
    public GameObject Collision_Obj;
    public GameObject Spawner_arrow;
    public GameObject Arrow;
 
    public float Speed = 1;
 
    public int HP = 10;
    public int Damage = 2;
    public int storona = 1;
 
    private Castle_Red Castle_Red_Script;
 
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        Castle_Red_Script = Castle_Red.GetComponent<Castle_Red>();
    }
 
    void Update()
    {
        rb.velocity = new Vector2(storona * Speed, rb.velocity.y);
    }
 
    public void TriggerEnter()
    {
        animka.SetBool("Attack", true);
        Speed = 0; 
    }
 
    public void Spawn_arrow()
    {
        animka.SetBool("Wait", true);
        animka.SetBool("Attack", false);
 
        Instantiate(Arrow, Spawner_arrow.transform.position, Quaternion.identity);
    }
 
    public void ZeroHp()
    {
        animka.SetBool("Wait", false);
        animka.SetBool("Attack", false);
 
        Speed = 1;
    }
 
    public void NotZeroHp()
    {
        animka.SetBool("Wait", false);
        animka.SetBool("Attack", true);
    }
}
Стрелы:
public class Arrow_meh : MonoBehaviour
{
    public Skelet_meh Skelet_script;
    public Health Enemy_health;
    public Skelet_trigger_meh Skelet_trigger_Script;
 
    public GameObject Skelet;
    public GameObject Skelet_trigger;
 
    public int storona = 1;
    public int enemy_hp;
 
    public float Speed = 0.1f;
 
    void OnEnable()
    {
        Skelet_script = Skelet.GetComponent<Skelet_meh>();
    }
 
    private void FixedUpdate()
    {
        transform.position = transform.position + new Vector3(Speed, 0, 0);
    }
 
    private void OnCollisionEnter2D(Collision2D collision)
    {
        if(collision.gameObject.tag == "Red")
        {
            Enemy_health = collision.gameObject.GetComponent<Health>();
            Enemy_health.Hit_Damage(Skelet_script.Damage);
 
            enemy_hp = Enemy_health.HP;
 
            Arrow_Conflict();
        }
    }
 
    public void Arrow_Conflict()
    {
        if(enemy_hp <= 0)
        {
            Skelet_script.ZeroHp();
        }
        else
        {
            Skelet_script.NotZeroHp();
        }
 
        Destroy(this.gameObject);
    }
}
Триггера:
public class Skelet_trigger_meh : MonoBehaviour
{
    public Skelet_meh Skelet_script;
 
    public GameObject Skelet;
    public GameObject Skelet_arrow;
    void Start()
    {
        Skelet_script = Skelet.GetComponent<Skelet_meh>();
    }
 
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.tag == "Red")
        {
            Skelet_script.TriggerEnter();
        }
    }
 
    private void OnTriggerExit2D(Collider2D collision)
    {
        Skelet_script.animka.SetBool("Wait", false);
        Skelet_script.animka.SetBool("Attack", false);
 
        Skelet_script.Speed = 1;
    }
}

Ошибка animator is not playing an AnimatorController



0



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

Возможно, вам также будет интересно:

  • Animal crossing ошибка 2618 0513
  • Anim player blender ошибка
  • Angry birds transformers ошибка h01
  • Angry birds fight ошибка сети kpl как исправить
  • Angry birds 2 ошибка подключения лагерь орла

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

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