TylerTemp / SaintsField

A Unity Inspector extension tool focusing on script fields inspector enhancement
MIT License
148 stars 9 forks source link

AnimatorStateAttribute cannot get states from Sub-state machines. #9

Closed dragon122 closed 4 months ago

dragon122 commented 4 months ago

Animator's Sub-State machines are a great way to reduce clutter inside the Animator and is a must for any more or less sizable project. Sadly, AnimatorStateAttribute cannot provide states inside SSMs.

TylerTemp commented 4 months ago

Hi, thanks for reporting

Please upgrade to 2.3.3 to see if it's fixed.

Please note: upgrade to 2.3.3 won't break the current API, but AnimatorState that already serialized MIGHT be reset to blank, please manually sign again to fix it.

public class Anim : MonoBehaviour
{
    [AnimatorState, OnValueChanged(nameof(OnChanged))]
    public string stateName;

    [AnimatorState, OnValueChanged(nameof(OnChangedState))]
    public AnimatorState state;

    // This does not have a `animationClip`, thus it won't include a resource when serialized: only pure data.
    [AnimatorState, OnValueChanged(nameof(OnChangedState))]
    public AnimatorStateBase stateBase;

    private void OnChanged(string changedValue) => Debug.Log(changedValue);
    private void OnChangedState(AnimatorStateChanged changedValue) => Debug.Log($"layerIndex={changedValue.layerIndex}, state={changedValue.state}, animationClip={changedValue.animationClip}, subStateMachineNameChain={string.Join("/", changedValue.subStateMachineNameChain)}");
}

animator_state

dragon122 commented 4 months ago

Now every time I try to select a state from the dropdown list, it throws "ArgumentOutOfRangeException: Index was out of range" ("curIndex" aways = -1 in "AnimatorStateAttributeDrawer.cs" line 127) The script\animator is newly created, same code as in the example above.

TylerTemp commented 4 months ago

Oh god... I made a typo when fixing it...

Sorry, fixing it again... on the way...

TylerTemp commented 4 months ago

It's been updated to version 2.3.4. Please have a try (hope it's all good now. 😳 such an embarrassing bug)

dragon122 commented 4 months ago

Everything works perfectly. Great job and quick response. Keep up the good work!