- Home /
Animator override controller fails to play sprite animation
I'm making an isometric, 8-sided sprite controller - where each animation has 8 different directions.
I have a base animator controller that handles triggering which "direction" is playing (forwards, backwards, left, right, and diagonals).
Then I have different AnimatorOverrideControllers for each animation (e.g. walking, attacking etc).
My plan was to simply swap out the correct runtimeAnimatorController - like so:
public void SetAnimation(AnimationType animationType)
{
switch (animationType)
{
case AnimationType.Move:
Animator.runtimeAnimatorController = MoveController;
break;
case AnimationType.Attack:
Animator.runtimeAnimatorController = AttackController;
break;
default:
Animator.runtimeAnimatorController = IdleController;
break;
}
}
The actual animation appears to be set correctly (the sprite shows the correct first frame), and the base AnimatorController is also correctly working (the sprite updates its direction at the appropriate times).
HOWEVER, the animation is not playing. The sprite just stands there on the first frame of the animation.
I am sure this is something obvious that I'm missing. Any ideas?
P.S. There are no errors or warnings in the console. And the more I look into this, the more I'm certain that the issue is with the animation itself.. although again I'm not sure what it could possibly be!
Starting to get a little frantic with this..
Answer by lnwhitling · May 30, 2020 at 01:34 PM
Discovered the problem - which had nothing to do with how I was changing the animation controller.
In the base controller, that handles the "direction" state, I am updating an Int to represent the direction. But I had forgotten to uncheck the "allow animation to transition into self" flag (in the transition settings). So it was being repeatedly reset.
Really basic stuff, but it had been so long since I've done this, that I completely forgotten about that flag.