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 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 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.
answered Mar 9, 2018 at 23:26
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». В инспекторе все указано. Скрипт скелета:
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.
c# – Animator is not playing an animation controller