- Home /
Why are my animation transitions not always working?
I have several animations linked to my prefabs (which are enemy characters). My animations are for "Running" and "Idle".
For about half of my prefabs, even when the enemy stopped, the "Running" animation is still playing. For the other half, it transitions to "Idle" as it's supposed to.
Why is that happening? Why are some of the prefabs behaving erratically? Can it be linked to the fact that all my physics (and the whole script) are in Update() instead of FixedUpdate()?
Thanks in advance
Don't place Physics in Update()
Are you using Animator ($$anonymous$$ecanim) or Animation (Legacy)?
If the former, separate you Controller Script from anything else and force-feed it. $$anonymous$$eeping it trim keeps it responsive.
$$anonymous$$ake sure you setup Transitions properly; sounds like you animations are playing through to the end of the loop.
Hi there, thanks for your response.
I'm using Animator.
What is "Controller script"? Do you mean the part which has "SetBool("Running",false) ? Also what do you mean by "force-feed it"?
Thanks a lot
Thanks a lot for your explanation. Feel free to submit it as an answer.
Aye why not.
The last two sentences are probably the bits that do it :P Hope you haven't jumped the gun on accepting the answer :P
Leave a comment if you have further trouble.
Answer by meat5000 · Jun 03, 2014 at 01:16 AM
Yes that's the one.
I use my Controller Script as a barebones interface. Nothing else resides inside this script other than the logic to make my Animations run and a few variables, which I expose for use by other scripts. I use these other scripts to Push values to these variables via GetComponent; so Force-feeding.
For example
var joystickInput : Vector2 = Vector2(0,0);
//In Update()
animator.SetFloat("walkFloat", joystickInput.y);
animator.SetFloat("turnFloat", joystickInput.x);
This is all the code that is required to animate my character between 5 states of forward motion, 2 states of backward motion and blending with turn animations.
In this script 'joystick' is not actually connected to a Joystick. It is just a Vector2 that I am free to inject from other scripts. This means I can input values from any script, any controller or even take over the character control in some kind of event.
The Animation script remains very lean this way and so will always be responsive, never feel sluggish and never miss Animation triggers.
Do this and you are halfway there. The rest is making sure your Transitions are correct, in Animator and be careful with Exit Time parameter.
Also, If you set a Bool in animator, make sure to Unset it!
While setting the SetBool("IsWalking",true) in the script, I can see that the checkbox for IsWalking gets checked in the Animator Window when I start walking, but still the animation for Idle keeps going on. Why is that?
SetBool("IsIdle",false);
?
You must clear previously set parameters which may interfere.
If you still have problems utilise the concept of animation layering and weighting to have the animator override the idle animation completely.
There was no param by that time, issue was there was exit time associated with the idle animation.
It was an example :D Of course you should know what parameters you've used, there's no way I'd know without seeing your script!
It was supposed to re$$anonymous$$d you that if you set an idle parameter you must make sure to clear it when you want to enable something else.
Proper usage of Layer weighting can solve these issues also.
You must also make sure that there is a transition to the walking state available and that the conditions of your transitions are met.
This page links with the answer here.
I know this is almost 2 years old, but it's one of the first result when looking up "unity animator transition condition not working" on google so it might be interesting for those who look it up.
With Unity 5.X, there's currently a bug with the Animator with the "State$$anonymous$$achine Default State". (Do not confuse it with the Default State. Default State is the orange node while the State$$anonymous$$achine Default State is the orange arrow.) Basically, the State$$anonymous$$achine DefaultState is only used when the State$$anonymous$$achine initiate itself through the $$anonymous$$ono Behavior.
A possible "fix" for the bug (whenever it happens) is to change the State$$anonymous$$achine Default State and return it back to the previous one. (To change hte State$$anonymous$$achine Default state, right click on the node that is before the one which ignore the parameters in the chain of nodes, then select "Set State$$anonymous$$achine Default State". Click on any other node than the default one. Repeat, but this this time, click on the one you really want as default.
Seems to be an issue with Unity's animation where the State$$anonymous$$achine Default State ends up with a infinite priority level which then ignore all parameters' based priorities.
To anyone who comes across this in the future, again this comment is 2 years after the last one, $$anonymous$$ax_Bol has hit the nail on the head. I have a complex (for me) animator controller which works perfectly fine but now its come time to add enemy AI's and Ive spent the past 45 $$anonymous$$utes trying to figure out what the hell I did differently and couldn't get the enemy to simply enter his animation state with just a bool parameter. Changing default animation state to something else and then back to Idle fixed it immediately.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Help needed with scripting an enemy 0 Answers
how to make one script with different animations attached 2 Answers
Camera elements 2 Answers
Playing Animations? 1 Answer