Support for StateMachineBehaviour

Issue #10 resolved
Steamroller Studios created an issue

Is there any support or planned support for Mecanim's StateMachineBehaviour? The are viewed directly in the inspector just like a MonoBehaviour so i would think that extending support to them should be trivial.

Comments (3)

  1. Tor Esa Vestergaard

    Odin does support types derived from StateMachineBehaviour. This class looks like this in my inspector. As long as you have automatic editor generation enabled, Odin will create a custom editor for your StateMachineBehaviour derived types by default the moment you define them. If you do not have automatic editor generation enabled, you can force a generated editors rebuild from the "Window -> Odin Preferences -> Odin Inspector -> Editor Types" menu. If it still doesn't work, make sure that the type you want to enable Odin for has a checkmark in the type hierarchy in the same menu. If the type is not present in the hierarchy, it means there's already a custom editor defined for that type, and Odin will - for now at least - refuse to override that.

    If you mean serialization support for StateMachineBehaviour, as in a "SerializedStateMachineBehaviour", we seem to have missed that one. We will make sure to add it in the next patch. Meanwhile, you can easily create such a class yourself, should you have need of it - merely copy the below code.

    using Sirenix.OdinInspector;
    using Sirenix.Serialization;
    using UnityEngine;
    
    [ShowOdinSerializedPropertiesInInspector]
    public class SerializedStateMachineBehaviour : StateMachineBehaviour, ISerializationCallbackReceiver
    {
        [SerializeField, HideInInspector, ExcludeDataFromInspector]
        private SerializationData serializationData;
    
        void ISerializationCallbackReceiver.OnAfterDeserialize()
        {
            UnitySerializationUtility.DeserializeUnityObject(this, ref this.serializationData);
            this.OnAfterDeserialize();
        }
    
        void ISerializationCallbackReceiver.OnBeforeSerialize()
        {
            UnitySerializationUtility.SerializeUnityObject(this, ref this.serializationData);
            this.OnBeforeSerialize();
        }
    
        protected virtual void OnAfterDeserialize()
        {
        }
    
        protected virtual void OnBeforeSerialize()
        {
        }
    }
    

    Any types derived from the above class will be serialized by Odin.

    We hope this resolves your issue.

  2. Log in to comment