CustomPropertyDrawer use in CustomEditor

i have a property drawer for a class

[System.Serializable]
	public class Multicolor {
        ...

that lools like
1463070--79985--$multicolordrawer.png

so i can click on a color, and if it’s in the “used” category it will get moved to the “available” category and vice versa
that works as expected with the default inspector

however i’ve written a small custom editor/inspector where i want to make use of my property drawer

the customeditor is for the class

	public class Placeholder : MonoBehaviour {
		public Multicolor color;
                ...
       }

       [CustomEditor(typeof(Placeholder))]
       public class PlaceholderInspector : Editor {
               ...
       }

i display the propertydrawer in the customeditor using

SerializedProperty color = serializedObject.FindProperty("color");
EditorGUILayout.PropertyField(color);

it is displayed correctly, but when i deselect a Placeholder gameobject the Multicolor is not saved and always reverts back to the default value (this does not happen with the default inspector, there it is saved correctly)

i have tried wrapping the PropertyField call like this

		GUI.changed = false;
		SerializedProperty color = serializedObject.FindProperty("color");
		EditorGUILayout.PropertyField(color);
		if(GUI.changed) {
			EditorUtility.SetDirty(target);
		}

with no avail, i’ve also tried setting GUI.changed = true in my property drawer after making changes to the Multicolor instance it displays (thinking that maybe with a custom property drawer i would have to set gui.changed manually) – but that also doesn’t help

lastly i have also tried

SerializedProperty color = new SerializedObject(target).FindProperty("color");

but with that line of code i can’t perform any changes on my property drawer (clicking the color buttons on the gui has no effect; although i have not tried to debug what happens in the property drawer, maybe a change occurs but is instantly reset idk)

basically i have no idea how to make that change stick… i don’t sufficiently understand how/when to use GUI.changed and SetDirty, while i understand what this stuff does in principle the documentation is a bit lacking

lastly, other values in my customeditor which use default ui elements such as

var t = (Placeholder) target;
t.type = (Placeholder.ReplacementType)EditorGUILayout.EnumPopup("Type", t.type);

are stored correctly between select/deselect and play/stop, it’s just the propertydrawer that fails to save its value (on my custom inspector)

solution:

SerializedProperty p = serializedObject.FindProperty("color");
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(p);
if(EditorGUI.EndChangeCheck())
    serializedObject.ApplyModifiedProperties();
1 Like