Is there a direct way (using hash codes) to determine if animator X is currently in sub-state-machine Y on the base layer? I’ve noticed that the members of AnimatorStateInfo have changed, most notably “nameHash” is deprecated and there is now “shortNameHash” and “fullPathHash”. However, I don’t think I need either of those but only the “direct parent” (the encapsulating SSM) of the current state.
If this doesnt exist yet, I think it should - the distinction between states and SSMs should be transparent in a way.
I believe you can put a state machine behavior on the base layer of the state machine and get the current state that way. Override OnStateUpdate or whatever.
Seriously? Well, I could also keep an array of the names of the substates in the SSM, or do some other hack, but I want to avoid all that. It’s roundabout and suboptimal. Since sub-state machines do have names (in the editor), they should be queriable via a hash.
state machine behaviours allow you to do stuff like this now… I think the point is - instead of having some code that checks the current animator state and does a bunch of conditional stuff based on the current state… you can use state machine behaviours for a more event-driven approach.
so if you want some code to run when you enter/exit a state (or state machine), or code to run every frame during a specific state, or a script to do something at a particular time during a state, you can put a state machine behaviour on it and use the overrides available. There are events available for enter state, state update (every frame during the state), and state exit. Also some events for IK related stuff.
as well as state machine enter, and state machine exit.
but, if you really want to do it kind of the “old school” way, you could also just put one state machine behaviour on the base layer, and also use the overrides there. The overrides have the animator, and a few other parameters passed into them, which you can use to find the current state name, normalized time, etc (I think).
but, state machine behaviours are very handy… for example playing sounds, or other scripting at a specific time during an animation. you can put a SMB on the particular state, override StateUpdate and check the normalized time.
I agreee that SMBs are powerful, but this really has little to do with the topic of this thread. There are many situations where one needs to respond to an external event by checking the id/name of the current state. This should be equally simple if the state is actually a sub-state-machine.