I have a custom Editor for one of my ScriptableObjects. The only reason for the custom editor is so I can add a button at the bottom:
public override void OnInspectorGUI() {
DrawDefaultInspector();
if (GUILayout.Button("Create/Update ProBuilder Palette")) {
CreatePBPalette(serializedObject.targetObjects);
}
}
My question is, in all the examples for custom editors you are supposed to do this:
serializedObject.Update();
// do stuff
serializedObject.ApplyModifiedProperties();
Is this still necessary when using DrawDefaultInspector()? I currently donât have it there and it seems to be working just fine. I seem to be able to edit fields as normal and save the changes. Am I just silently causing issues for myself by not having it?
Well here is the code behind âDrawDefaultInspectorâ:
And it appears to call âUpdateIfRequiredOrScriptâ before drawing, and âApplyModifiedPropertiesâ afterward.
So no, you shouldnât have to call said boiler plate.
You can also see that âOnInspectorGUIâ just calls DrawDefaultInspector. So thatâs how it would behave if you didnât override âOnInspectorGUIâ:
I make extensive use of custom editors (both for Inspector and custom window) and none have either of those lines. Iâm using Undo._ and/or .SetDirty depending what Iâm doing and how much time I want to spend on it - I donât have a project open right now to confirm whether including the DrawDefaultInspector call or not has any impact but next time Iâm at it Iâll take a look. I was under the impression changes were flagged for saving from using Undo properly or SetDirty - hadnât occurred to me I might be omitting something important so Iâd like to know as well.