- Home /
Does Mecanim only change states after a frame?
So if I set a bool via the animator in script during an update method, does this get evaluated straight away in the mecanim controller or will the state change only occur after the update has finished?
I basically want to know how long the next animation will be in length (not normalized) so I can block input while it is playing, however I am not sure if I should be looking at CURRENT animation info or NEXT animation info after the setting of the bool.
Answer by Tehnique · Jul 28, 2014 at 09:28 AM
For blocking input, just make hashes for all animations that you want to block input for, put them in a list, and before accepting input, check if any of those animations are playing; and if so, ignore input. More info on hashes here.
EDIT: According to this (chart at the bottom), animation is updated after Update, and just before LateUpdate.
It is not a complete block I am after, I still need to listen for user input just not action it, as if they press PUNCH then $$anonymous$$IC$$anonymous$$ I need to make sure before the PUNCH animation ends it begins to transition into a $$anonymous$$IC$$anonymous$$, but I do not want it to process the $$anonymous$$IC$$anonymous$$ straight away, so basically I have an internal script bool which indicates if I am able to process the given input or not, however I need to basically wait 75% of the animation time then transition, hence why I need the animation time. As some animations may be 1 second, others may be 1.5 so the time delay is different for each.
You can do this with triggers. Basically, a trigger is a one shot bool for mecanim. A trigger is set from your code (like setting a bool to "true"), and once a $$anonymous$$ecanim transition consumes it (consumes = uses it as a condition), it is set back to false automatically. Triggers were recently introduced, and are very useful. $$anonymous$$ore on them here.
You can set your transition (from PUNCH to $$anonymous$$IC$$anonymous$$) conditions to "ExitTime = 0.75" and "$$anonymous$$icked" (this is the trigger), then set "$$anonymous$$icked" in the script, and once the time of PUNCH gets to 0.75, you will automatically transition to $$anonymous$$IC$$anonymous$$ (because the "$$anonymous$$icked" trigger is true and the PUNCH animation has played to the ExitTime).
Yep I had a forum post on that topic, however for the sake of this question can we look back at the original topic, does $$anonymous$$ecanim make its transition to the next state the moment you set a var or does it only take that change into account after the update scope has ended for the game object?
I'm not 100% sure, but according to this, it should happen after Update, just before LateUpdate.
I had not seen the flow chart at the bottom, do you want to put that down as the answer and will give you the points.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Mecanim Making an NPC walk 1 Answer
Mecanim Networking 0 Answers
How to access Blend Tree "speed" in Mecanim from C# 0 Answers