- Home /
unity animator transition keeps transitioning to beginning of animation
I have an animation tree that looks something like this:
JUMP(If whatAnimation = 3)
^
|
|
ANY STATE --------> Walk(If whatAnimation = 2)
|
|
V
IDLE(If whatAnimation = 1)
And some code that looks somewhat like this:
if (playerIdle) {animator.SetInteger("whatAnimation", 1);}//Transition to idle animation
if (playerWalking) {animator.SetInteger("whatAnimation", 2);}//Transition to walk animation
if (playerJumping) {animator.SetInteger("whatAnimation", 3);}//Transition to jump animation
However, when I run the code, it keeps playing the first few frames of animation over and over again when it transitions. Why does this happen, and how can I fix it?
EDIT: I actually have about a dozen more animations that are set up in a similar way to this, so that is why I don't want to individually transition from one animation to another.
Answer by Tecnophobe · Apr 09, 2019 at 06:15 PM
Your problem is linking everything to "any state". "Any state" includes the actual animation.
Here's a scenario. You are currently idle. But then, you start walking. So...
IDLE -> ANY STATE (walking == true) -> WALK
Now you are walking. But, the walk integer is still true. So...
WALK -> ANY STATE (walking == true) -> WALK
Causing the walk animation to repeat from the start.
As for a solution, the usual way is to link all animation to an "idle" animation, instead of to ANY STATE. I highly recommend doing this.
But it sounds like you might be crazy invested in connecting everything to ANY STATE. This is not impossible, to do this add a "changeAnimation" trigger to all animation conditions, and set this trigger when you want the animation state to change. Something like that might work.
Answer by theperm327 · Mar 13 at 08:51 PM
Yeah! Thanks. I had the same problem. I was reading other boards and nobody had the right answer. You're awesome!
Your answer
Follow this Question
Related Questions
How to access and modify an animator state transition in runtime? 1 Answer
Bug animation transitions, or am I the bug? 0 Answers
How to deal with the Transitions If I have ten or more kinds of Animations in Unity Animator? 0 Answers
0:15 transition to 0:60 animation not working 0 Answers
Animation Running Game 0 Answers