- Home /
Transition from all substates in substate machine in mecanim
I have a substate machine that contains a series of idle animations (about 6 of them currently) that are randomly selected upon entering the idle substate machine by a simple substate machine behavoir script.
According to this : http://blogs.unity3d.com/2015/02/11/having-fun-with-the-new-mecanim-features/
I now want to transition from any of these states into a locomotion substate machine when the speed parameter is greater than zero.
I tried connected the 'idle' substate machine with the 'locomotion' substate machine in the layer above the idlesubstate machine using a transition with the condition of speed > 0.
However the idles just keep playing and the transition is never done.
How do I get any of the idle animations in the idle substate machine to be immediately interupted when speed >0 and transition into the locomotion state without selecting each on and creating a transition on each one through the (Up) Base Layer and into locomotion? Because this doesn't seem a very good way to do it especially when I intend to expand the number of idle states in future.
Answer by Baste · Aug 22, 2015 at 09:50 AM
The state machine system has some very, very strange desicions built into it.
Setting up a transition between two substate machines does not actually do anything on it's own. You also have to use the entry/exit nodes.
So if you have a state machine transition from the substate machine Idle to the substate machine Locomotion, that will only kick off if the exit node in the Idle machine has been entered.
Sadly, there's no possible way to set up a transition which means "from any state within this machine, transition to the exit node if the speed variable is greater than 0", as the any state node within a state machine is the global any-state.
So as far as I've been able to work out, you have to have a damn transition out from every idle state. It's a real pain.
Yes, I have many idle states, mainly because 1. There are several characters using the same animator and I don't like it when their idle animations match up and their idle animations syncronize. 2. Because depending on whether they are happy, sad, angry or normal they will have different idle stances.
Regardless of what idle animation they are in however I need them to start walking when they are commanded to by the RAIN AI I am using.
So as described above I have all the idles in a separate substate machine but I've only been able to achieve the behavoir I am looking for by running a transition from every single idle state using the condition speed >0 or direction > 0 (because they might turn but not move) so that means two transitions for every idle state, which is a lot of work.
If each of your idle animations are going to function identically, you could set this up with a blend tree. Simply replace all of the transitions to and from the idle states with a transition to the blend tree. Let the tree use the old random parameter to pick the correct idle animation.
It's not quite what blend trees are meant to do, but it'll do the job.
Thanks Baste, I actually had something like that setup in unity 4, but it wasn't very pretty so since unity 5 came out and broke my old mechanim controller I thought I'd re-engineer it from scratch the way 'its supposed to be done'. Of course now I find out that there is no way its ment to be done only ways to bodge the behavoir. I'm quite disappointed because I would have thought multiple idle states and transitions to walking would be something just about everyone uses.
Anyone also looking for this feature, here is a feedback item for it. Please add some votes to maybe get it some attention:
http://feedback.unity3d.com/suggestions/mecanim-any-sub-state-node-in-sub-states
Your answer
![](https://koobas.hobune.stream/wayback/20220612000934im_/https://answers.unity.com/themes/thub/images/avi.jpg)