Hi,
In the legacy system I had full control over animations. However it seems to me that I lost control in mecanim. Or most likely I do not know how to control, anyway. At some condition I want all states of “mecanim state machines”, to be stopped immediately whether an animation is playing within a state or transition. I want abrupt “full stop” of all animations. Then I want to play state of my choice. Like this:
Right now, whether I do or do not, it does not matter. A state plays fully, then change into another state. But I do not want it. It is VERY necessary for me to stop the playback of a state, in the middle of playback. Where will I stop playback, depends. Lets say user pressed “Y”. Then no matter which animation player is playing or not, user must stop current animation in the middle of playback. Then play animation associated with “Y” key.
So you see, stopping playback could happen 0.1 or 0.2 or 0.5 or 0.7 etc normalized time. So don’t tell me to split out animations to set a bunch of states for them, as it does not work.
Whether will I use mecanim for my project or go back to legacy, depends upon answer. unity gurus, could you shed some light on this?
After a through R & D, I have found a way of doing this, and a possible bug within mecanim system too.
When you call animator.play(statename in string or hashcode int);
No matter, on which state you are, unity will jump abruptly on the state which you passed in animator.play() method. This is exactly what I want. But you can not stop all animation with something like animator.stop(), like we did in legacy system.
Now lets talk about bug. Lets consider there are three states. state A, B and C. If we call,
animator.play(stateA);
while we are in any of other states, its no problem.
BUT,
if we are in stateA, meaning stateA animation is still playing, then we call,
animator.play(stateA);
So, normally we want this stateA animation to be played again. In reality it does not happen. Test yourself! You will witness something wrong.
What I did to solve this:
I duplicated the concerned states. Meaning now I have “stateA” and “stateA_Duplicate”.
Then I switch between them in code. Hope this helps for anybody facing similar problem.