Getting SubState in an animator in code

Hi. I’m having trouble getting SubState in Animator

This is what i do so far, and it just doesn’t detect the SubState that’s in the Animator
All the states inside this SubState just doesnt get logged

sm.stateMachines returns 1, and sm seems to be the stateMachine for the layer.
I was hoping there’s a ChildAnimatorState.stateMachines and check its Length, to know if it’s a substate, but this is not a thing?

Cheers

1 Like

Woops. I’m stupid
Apparently all u gotta do is

if(sm.stateMachines.Length > 0)
            {
                foreach(ChildAnimatorStateMachine cas in sm.stateMachines)
                {
                    Debug.Log(cas.stateMachine.name + " : " + cas.stateMachine.stateMachines.Length);

                    foreach(ChildAnimatorState j in cas.stateMachine.states) //for each state
                    {
                        BlendTree bt = j.state.motion as BlendTree;
                        if(bt)
                            continue;

                        stateClips[j.state.name] = j.state.motion.name;
                        Debug.Log($"SUB {j.state.name} : {j.state.motion.name}");
                    }
                }
            }

Notice i’m accessing the ChildAnimatorStateMachine cas, then ChildAnimatorState cas.stateMachine.states