When using DrawDefaultInspector do I still need boilerplate?

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’:

4 Likes

Awesome, thank you!

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.