Search Unity

How to know what makes scene dirty?

Discussion in 'Editor & General Support' started by Deadcow_, Jun 13, 2019.

  1. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    So, what the title says. Every time I start editor my main scene is marked dirty.
    I tried to isolate all my editor code and double checked if there is any SetDirty or Undo methods which may cause it but unable to find the culprit yet.

    I'll dig it up eventually but just wondering if there is some way to check what is marking scene dirty, some editor event accessable via reflection or something :)
     
  2. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Not yet. I think Unity knows about this specific issue developers have to deal with so maybe they implement something in the future.

    Until then, the only thing is to scan the code base for calls to Undo, SetDirty, SerializedProperty, PrefabUtility and probably a few other API calls used in different utilities.

    One thing to try, however, would be Undo.postProcessModifications. With this callback many of the changes in a scene become visible, but you would need to register to te callback before the change is made and of course it only catches calls registered via Undo.

    A potentially good solution would be an event which is triggered by Unity whenever the scene is marked dirty. Tool developers could then walk the callstack to find the culprit.
     
    Deadcow_ likes this.
  3. John_Leorid

    John_Leorid

    Joined:
    Nov 5, 2012
    Posts:
    651
    For everyone stumbling over this thread, the callback exists now:

    EditorSceneManager.sceneDirtied += SceneDirtied;


    And with the three dots in the console, enabling full call stacks (thanks for the hint, Xarbrough) I was able to track it down to ProBuilder - which seems to optimise (and dirty) it's meshes on every performed Undo/Redo.
     
    Zaddo, bobuc, Artemko_one and 4 others like this.
  4. Deadcow_

    Deadcow_

    Joined:
    Mar 13, 2014
    Posts:
    135
    Oh my, that's super helpful, thanks!
     
  5. Wappenull

    Wappenull

    Joined:
    Oct 29, 2013
    Posts:
    51
    This was able to help me track unknown scene dirty, where
    Undo.postprocessModifications
    cannot track.

    Enable full stack trace here as above comment suggested:
    upload_2021-6-6_11-40-59.png

    The result will look like this. It was from my dumb "[ExecuteAlways]" script. Sigh...
    upload_2021-6-6_11-41-56.png

    For the sake of completeness, I will include my tracker script for non-coder to copy too. (Because I know you like to copy-paste, it is satisfying!)
    • Copy and add this file into editor script folder. (like Assets/Scripts/Editor)
    • Then from upper menu, select Tools->Wappen->Toggle scene change tracker
    https://gist.github.com/wappenull/acfd388185c543bfe8fa98f6ab07f317