Editor Shutdown Callback exists?

Hello dear Community!

I have a set of editor scripts which perform operations upon the scriptable objects, which are saved as assets.

The problem is, there are thousands of function calls per Editor Update frame, where each one modifies a specific asset/subassets (many of several hundred assets).

In order to serialize changes, I must mark the scriptable object as “Dirty” and do AssetDatabase.SaveAssets().

Saving assets doesn’t seem a hard task, but setting an object as “dirty” causes a signifcant lag. This is the issue even if it happens once, not every frame - it still lags for 1 second though the asset isn’t big at all.

Without this “setDirty” call, even if I save the project (Ctrl + S) and quit unity, when I come back, the changes in assets would not be saved.

Is there a specific callback for an editor, which happens on program shutdown? So that I can set dirty on modified assets, but only once, upon Unity is going to close, and not every time, after some sequences of actions?

Hey,

You could try using OnWillSaveAssets to add your assets to the list that needs to be saved.
This is called when changing scenes, when you save a scene and if I’m not mistaken when Unity is closing.

public class MyAssetModificationProcessor : AssetModificationProcessor
{

public static string[] OnWillSaveAssets(string[] paths)
{
    
    return paths;
}

}

Hope this helps.