Draw rect color disappearing when any input is detected

Hey folks,

I’ve got a simply Property Drawer script, which, amongst other things, Draws a coloured Rect around the property. However, I’m having an issue that if I’ve got the inspector window in focus and then use the scroll wheel the colored Rects lose their color. In a few seconds the color returns to them, but if I scroll the wheel again then the color vanishes.

After testing this, it seems that the Rects disappear while any input is happening. So if I continue scrolling they won’t appear until I stop. Same for clicking.

Script:

        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            GUIStyle minStyle = new GUIStyle(EditorStyles.numberField);
            GUIStyle maxStyle = new GUIStyle(EditorStyles.numberField);

            float padding = position.height * 0.8f;

            Rect borderRect = new Rect(position.x,
                position.y,
                position.width,
                padding);

            Rect areaRect = new Rect(position.x + 2,
                position.y + 2,
                position.width - 4,
                padding - 4);

            EditorGUI.DrawRect(borderRect, Color.black);
            EditorGUI.DrawRect(areaRect, Color.blue);
}

Screenshot, on the left is how it should appear and on the right is what happens if I use the scroll wheel.

Ah okay, so I’ve got to the bottom of this problem, it’s detailed in an answer here:

https://answers.unity.com/questions/1311926/texture2d-in-scriptableobjects-property-drawer-exp.html?childToView=1401566#answer-1401566

And the solution is to simply add this to the bottom of your Property Drawer class

        public override bool CanCacheInspectorGUI(SerializedProperty property)
        {
            return false;
        }