How does one work around the lack of a (local) sub-state machine "Any State" node?

In my Mecanim Animator, I’m replacing my single idle state with a sub-state machine that randomly selects from many idle states. As described at the start of this unity blog post, the setup for inside the sub-state machine is something like this:

Now this works, but the problem I’m having is with letting each idle state exit based on the conditions of the transitions from the sub-state machine itself. This whole thing needs to transition to move, jump, attack, etc. If there was an “Any State” node that was local to the state machine, I would only need to repeat those conditions once, in a transition to Exit. I see lots of feedback items about this, but nothing on the roadmap. In the above linked blog post, Silvio and Pierre-Paul are talking about the same problem a few comments down.

So the only alternative from within the Animator itself seems to be repeating every transition’s conditions on every idle state. Considering I have about 5+ transitions from the sub-state machine, each with multiple conditions, you can see how redundant/anti-DRY this is (and prone to errors). Especially as additional idle states and transitions are added.

Is there a way around this that I’m missing?

The only possible workaround I’m considering now, is to do it by code using a state machine behaviour. I could manually check the conditions/parameters in OnStateUpdate, and give that behaviour to all the idle states. If any of the conditions are true, it would go to Exit. So it’s like a local Any State, but driven by code. That way I’d only need to change the conditions in one place rather than 15+ places. It seems a bit silly to have to do it that way.

But there IS a local “Any State” and it’s working(I checked). The problem is that you can’t make transitions from “Any State” to Exit node or to Upper level. But I think you can make transition from “Any State” to just empty state and from this empty state to whatever you want(didn’t check yet). Still a little bit hackish but may just work. Anyway I don’t see big difference with usage of blendtree for that…

The “Any State” within a sub-state machine is global. It does not mean “Any State within this sub-state machine” unfortunately, and there is no node for that. I ended up coding a behavior that manually checks the transitions, as mentioned, which is a workaround for now. Transitions in code instead of the Animator; in one place instead of repeated 15+ times.

Others looking for this: [1] [2]
Latest response was that this feature is “not planned right now”.
Oh well.

Yeah, @jwinn you’re right! My first test was incorrect.

There’s actually a pretty elegant work around for not having local substate machine any state nodes.

What I’ve been doing in my project is using a State Machine Behavior with OnEnterStateMachine and OnExitStateMachine to set an int animator parameter to indicate which layer or SSM I’m on.

Then, on your any state transitions, you can add this int variable to all your transitions to control the transitions to just the layer or SSM you want.

If that doesn’t make a ton of sense, I’d be happy to make a YouTube video on how to do this. I may be misunderstanding what you’re trying to do though

6 Likes