Custom Editor/Custom Property Drawer combo, breaks Enable button

I have created a custom Property Drawer, which works fine when the MonoBehavior holding it uses the default Inspector. However, when I try to use a custom Editor, that display nothing but this property drawer: the enable button for the MonoBehavior no longer works properly!

I’m not sure what I could be doing to cause such an issue. Since it works using the default inspector, this lead me, initially, to believe the problem lay with my CustomEditor, and not the property drawer itself.

But further testing shows the custom editor ONLY messed up the Enabled button, if CustomProperty Drawer needs to take some particular action. (It should do this action even for the standard inspector, so I’m not sure why it’s behaving differently.)

In particular, the CustomProperty drawer needs to build an array of strings, in a sub-property of the SerializedProperty. When I remove this array-rebuild section, as a test, the enabled button works property (but changes are not stored). This particular section is noted in the custom property drawer code below (near the bottom). I note again, this actually seems to work fine, the ONLY issue is that it breaks the enabled button when used in a custom editor.

What am I doing wrong? How can I resolve this issue? Why do I get different effect (eg. enable button) for the property drawer when using a custom Editor vs the standard Inspector?

OptionNames.cs

//!This class has a custom property drawer
[Serializable]
public class OptionNames
{
    public string[] selectedOptionNames;  
    public string[] fullList;
}

TestMono.cs

[ExecuteInEditMode] //just so we can see debug log post when enabled state changes
public class TestMono : MonoBehaviour {

   public OptionNames options;// the only member of this class, public and displayed in inspector

   private void Reset()
   {
       Debug.Log("reset");
       options = new OptionNames();
       options.fullList = new string[4] { "a", "b", "c", "d" };
       options.selectedOptionNames = new string[2] { "a", "d" };
   }
   private void OnEnable() { Debug.Log("enabled"); }
   private void OnDisable() { Debug.Log("disabled");  }
}

TestMonoEditor.cs

[CustomEditor(typeof(TestMono))]
public class TestMonoEditor : Editor{

    public override void OnInspectorGUI()
    {
        SerializedProperty options = serializedObject.FindProperty("options");
        EditorGUILayout.PropertyField(options, new GUIContent("options"));
        serializedObject.ApplyModifiedProperties();  //stack traces of the debug.Log commands in the monobehavior show this line is invoking the enable state toggle BACK to the state it was before I clicked it.
    }
}

OptionNamesDrawer.cs

[CustomPropertyDrawer(typeof(OptionNames))]
public class OptionNamesDrawer : PropertyDrawer
{   
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
           
        SerializedProperty listprop;
        SerializedProperty fullListProp;

        listprop=property.FindPropertyRelative("selectedOptionNames");
        //get the full list from the serialized object, as a simple string[]
        fullListProp = property.FindPropertyRelative("fullList");
        string[] fullList = new string[fullListProp.arraySize];
        for(int i=0;i<fullList.Length;i++)
        {
            fullList*=fullListProp.GetArrayElementAtIndex(i).stringValue;*

}

StringListAsMaskProperty(position, listprop, label, fullList);
}

//! The SerialedProperty is an array of strings containing only the selected Items.
public static void StringListAsMaskProperty(Rect r, SerializedProperty prop, GUIContent label, string[] fullList)
{
if (fullList == null) return;
if (prop == null) return;
int mask = 0;
int len = prop.arraySize;
for (int i = 0; i < len; i++)
{
string s = prop.GetArrayElementAtIndex(i).stringValue;
for (int j = 0; j < fullList.Length; j++)
{

if (fullList[j] == s)
{
mask = mask | (1 << j);
}
}
}
mask = EditorGUI.MaskField(r, label, mask, fullList);

//return; // returning here allows enable state to work
prop.ClearArray();

int count = 0;
for (int j = 0; j < fullList.Length; j++)
{
if ((mask & (1 << j)) != 0)
{
prop.InsertArrayElementAtIndex(count);// removing this allows enabled state to work! (remark out clear array above, to keep the list from becomeing empty- changes wont work though, obviously)
prop.GetArrayElementAtIndex(count).stringValue = fullList[j];
count++;
}
}

}

}//end optionNamesDrawer class

SerializedObject.ApplyModifiedProperties() works in conjunction with SerializedObject.Update().

In your TestMonoEditor.OnInspectorGUI method:

serializedObject.Update();

SerializedProperty options = serializedObject.FindProperty("options");
EditorGUILayout.PropertyField(options, new GUIContent("options"));

serializedObject.ApplyModifiedProperties();