Animation state going back to Idle?

This is a kind of update on my previous question, which was a problem I was having with animation states. (How to looping animation states? - Unity Engine - Unity Discussions) ← this is the thread.

So basically what happened, is originally I thought that the run animation just finished, and stayed on the “Run” state. Then DavidGeoffroy misunderstood the question, and thought that it was going back to the “Idle” state when the running animation finished. After going back into Unity, I realized that that’s actually what was happening.

I did post a reply on that question, clearing things up, but since I still haven’t received a reply from anyone on it, I decided to make a new question, directly addressing the issue.

I have “Loop Time” checked on the Run animation (now renamed to “Walk”), and I also have “Has Exit Time” checked on the transition from Walk to Idle. If I uncheck that, the Walk animation doesn’t play at all when I move, so I kept that checked. Same with Loop Time.

I even tried going into my code, to see if there might have been something that unintentionally causes the states to switch, but there isn’t.

Do you really have a proper condition on the transition from Walk to Idle? Because, if you need Has Exit Time checked to get it to play, that would indicate that the condition matches immediately. If you remove the transition back to idle, does the animation play correctly?

Are you using any Any State transitions? These can sometime mess up other transitions.

An excellent way of debugging animations is to keep the Animator window open, then you’ll see all changes to parameters and to states of the animation state machine.

1 Like

I have a “Run” parameter, and I set it to true if the “A” or “D” button is pressed (for moving left and right), it sets to false when the buttons are not pressed, and also when the player collides with something on the horizontal (x) axis.

When I delete the transition back to Idle, the animation loops properly, but it does so as soon as I hit “Play”, and not when I press a button.

Also, I do not quite understand what you mean by “Are you using any Any State transitions”. I thought the only way of animating in Unity, was to switch between states, with each state having an animation assigned to it (I have a transition from the Idle state to the Walk state, and back to Idle.).

So it must be the transition that is faulty. Do you have a couple of screenshots from the Animator window, one for each transition for example?

As with regards to “Any State”, you can make transitions from the “Any State” to an animation clip in the Animator. It works more or less like when you have a normal clip transition, but it will trigger the moment anyone of its transitions’ conditions are fulfilled, no matter which clip is playing. So, it will break away from the normal transition flow.

Here are screenshots for both transitions. Imgur: The magic of the Internet

Also, I don’t have any transitions going from the “Any State” block.

Hmmm, can’t see any obvious errors.

This is how I would have set up Walk → Idle:

  • Has Exit Time: Unchecked
  • Fixed Duration: Unchecked
  • Interruption Source: None (This might be the culprit)

The rest would be the same as you already have them.

I’ve set them to what you listed, and the animation plays, but it sort of snaps back to idle. And I don’t know why, but when I’m in “Play” mode, the animation states don’t have the blue progress bars in them. Is there a way to set it so they show?

Anyway, back to the original problem. When I move, I can just make out the first frame of the Walk animation showing up, but it’s only for a split second, and then it’s back at the idle state where both feet are straight on the ground. (this only happens when “Has Exit Time” is unchecked")

A very strange problem indeed :slight_smile: And the Run variable actually remains as true and doesn’t get reset? If you go to the Animator Window while running the game, and then you click on the Run variable to set it to true, does the animation play correctly?

If the Run variable is reset and you have Has Exit Time enabled, then the complete animation should run before doing the transition. So it is most likely that variable is the culprit…

I don’t know how to check whether the Run variable remains true or resets.

When I click on the Run variable to set it to true, the animation does play correctly.

I’ll check my code again, and let you know if I find any faults or mistakes.

If you have the Animator window open while running, showing the parameter part, then you’ll see the current state of all it’s parameters.

The parameters don’t change.

Also, if I remove the else statement which sets the parameter to false, the animation loops after it plays once, so the else statement is somehow running even when the button is held down after the animation plays once.

The answer turned out to be a lot simpler. Honestly, at this point, every time someone with a lot of experience, can’t figure out the issue, it should be obvious that something is overlooked that you haven’t informed them about.

I had the if statement setting the parameter, set to “GetKeyDown” whereas it should’ve been “GetKey” since the “Down” part only registers for the first frame the button was pressed.

Dude, thank you so much for your help! I really appreciate it.

Hopefully this question can be of help for anyone facing this issue in the future.

for future: one of reason can be parameter 0 in conditions. if 0 is stand and 1 is walk, use 0.5 it help with my problem