Detecting scene changes in ScriptableObject Editor Script

This might be super simple but I can’t find a way to do it so far.

Basically, I have a ScriptableObject editor class which isolates all un-selected object, and vice-versa. What I need to do is trigger an event when I manually select another scene to work on, so that I can show a messageBox which will ask me if i want to un-isolate all objects before changing scenes.

The only part I can’t figure out is how to setup a callback for manual scene changes in-editor…if anyone knows how to achieve this please feel free to share the love haha

Thanks for your time!

Stephane

After digging into it a little more, I found a script that does exactly what I needed:

using UnityEditor;
using System.IO;

public class MyAssetModificationProcessor : AssetModificationProcessor
{
    public static string[] OnWillSaveAssets( string[] paths )
    {
        // Get the name of the scene to save.
        string scenePath = string.Empty;
        string sceneName = string.Empty;

        foreach( string path in paths )
        {
            if( path.Contains( ".unity" ))
            {
                scenePath = Path.GetDirectoryName( path );
                sceneName = Path.GetFileNameWithoutExtension( path );
            }
        }

        if( sceneName.Length == 0 )
        {
            return paths;
        }
		
	    // DO WHAT YOU NEED TO DO HERE.
        // FOR EXAMPLE, CALL A STATIC FUNCTION FROM ANOTHER CLASS
		

        return paths;
    }
}

Hope this helps anyone else looking to do this out. If you have any questions, feel free to ask :slight_smile:

You need to use an EditorWindow and the message EditorWindow.OnSelectionChange. Then you can parse the selection using the Selection class.