Search Unity

DrawDefaultInspector triggering autosave

Discussion in 'Editor & General Support' started by Marko-Ravnjak, Jun 28, 2022.

  1. Marko-Ravnjak

    Marko-Ravnjak

    Joined:
    Oct 2, 2015
    Posts:
    13
    Hi,

    I have a custom editor (EditorWindow) which opens a prefab for editing (via PrefabStage, AutoSave is enabled) and is hooked on prefab save for some postprocessing (I generate a data asset based on the prefab content). On the OnGUI call for the editor I also wanted to render inspector for the generated data asset. I tried doing it like this:


    Code (CSharp):
    1.  
    2. private readonly UnityEditor.Editor levelBlockEditor;
    3. levelBlockEditor = UnityEditor.Editor.CreateEditor(dataAsset);
    4. // in OnGUI
    5. levelBlockEditor.DrawDefaultInspector();
    6.  
    This works, however, calling DrawDefaultInspector somehow triggers save and serialization logic. I'm guessing inspector is somehow calling SetDirty, which in response is triggering autosave.
    My first idea was that we have a (poorly written) custom drawer or something which accidentally calls SetDirty, but even if I [HideInInspector] on ALL members, the same thing happens.

    Any ideas who/what/why?

    Thanks!
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,851
    As far as I understand, inspectors serialise and deserialise data every repaint, alongside doing the dirtying in the context of serialized properties.

    When combined with prefabs, that have their own wonky serialisation, this might induce some odd behaviour.

    Could be wrong; this is just my understanding.