OnValidate on MonoBehaviours or ScriptableObjects does not get called for T fields rendered by OdinValueDrawer<T>

Issue #501 new
Jeffrey Campbell
created an issue

Is there anything additional that a developer would need to do for a class implementing OdinValueDrawer<T> to properly trigger OnValidate for MonoBehaviours or ScriptableObjects that have a field for T. We seem to have found a bug where in Unity 2018.3.3f1 using OdinInspector 2.0.5, OnValidate doesn't get called for fields being rendered by an OdinValueDrawer.

I've included a barebones example below that should help a developer reproduce this issue.

using System;
using UnityEngine;

namespace _Tests
{
    [CreateAssetMenu]
    public class TestScriptableObject : ScriptableObject
    {
        public TestSerializedObject objOne;

        [SerializeField]
        private TestSerializedObject objTwo;

        private void OnValidate()
        {
            Debug.Log("TestScriptableObject.OnValidate fired");
        }
    }


    [Serializable]
    public class TestSerializedObject
    {
        public string objName;
    }
}
using UnityEngine;

namespace _Tests
{
    public class TestSerializedMonoBehaviour : MonoBehaviour
    {
        public TestSerializedObject objOne;

        [SerializeField]
        private TestSerializedObject objTwo;

        private void OnValidate()
        {
            Debug.Log("TestSerializedMonoBehaviour.OnValidate fired");
        }
    }
}
using Sirenix.OdinInspector.Editor;
using UnityEditor;
using UnityEngine;

namespace _Tests.Editor
{
    public sealed class TestSerializedObjectDrawer : OdinValueDrawer<TestSerializedObject>
    {
        protected override void DrawPropertyLayout(GUIContent label)
        {
            ValueEntry.SmartValue.objName = EditorGUILayout.TextField(ValueEntry.SmartValue.objName);
        }
    }
}

Comments (0)

  1. Log in to comment