I do some scene maintenance in my games using editor tools. When the user saves a scene, I look through its objects and modify them if needed.
5.3 has inadvertently complicated this process with multi-scene editing. Great feature- but now that multiple scenes can be saved together, it can be very difficult to determine which scenes are being saved under which names. Determining when existing scenes are saved under new names is now especially tough/impossible in some cases.
This process could be made simple if a new callback was added to the AssetModificationProcessor class:
public static void OnWillSaveScenes(Scene[ ] scenes, string[ ] paths)
Now that we have “Scene” objects to work with, we can just pass these into a method like so. The corresponding “paths” array would be the new file paths associated with each scene being saved.
Other ways this could be tackled might be an “OnWillSaveScene” callback that passes in a single Scene/path at a time, or just a change to the existing “OnWillSaveAssets” callback to pass in object references to these assets being saved. However, right now I’d prefer the first approach.
Hey Unity
- Any chance we could see something like this, now that the (great) new feature had made some things complicated?
If something like this was implemented, ideally it would be called every time a scene was saved (which seemingly isn’t the case for OnWillSaveAssets() ).
This includes cases like:
- Saving a new scene to a new path
- Saving a new scene over an existing scene
- Saving an existing scene (normal saving)
- Saving an existing scene to a new path (“Save As”)
- Saving an existing scene over another existing scene
Hi,
We are working adding various callbacks in both the editor and at runtime.
For this I would suggest something like
EditorSceneManager.onSceneWillBeSaved += OnSceneWillBeSaved;
private bool OnSceneWillBeSaved(Scene scene, string path)
{
bool isNewPath = !System.IO.File.Exists(path);
bool isNewScene = scene.path.Lenght == 0;
if (isNewScene && isNewPath)
// Saving a new scene to a new path
else if (isNewScene && !isNewPath)
// Saving a new scene over an existing path
else if (!IsNewScene && scene.path == path)
// Save existing scene to same path (Normal save)
else if (!isNewScene && isNewPath)
// "Save As" of existing scene
else if (!isNewScene && !isNewPath)
// Saving existing scene over another existing scene
// redundant to test if scene.path != path because we already tested if they are equal
return true; // Return false to prevent the save
}
I am not sure if returning a boolean is a good idea but we can consider it.
I can’t say which version this will ship in, but it will not be a patch for sure.
Your solution would definitely meet my needs. Thank you for considering it!
Also, it’s informative to see how you guys would approach this.
-Cheers!
Hi! Any news on this feature? My work is still blocked by not being able to tell which scene is being saved in the editor.
I know you folks have your hands full.
Just wondering if we might see the solution you suggested in 5.4 or thereabouts.
Thanks!
The implementation is currently in internal review
Hi Steen! Sounds like a lot’s going on for you guys these days. I just want to check in on this. Any updates? I’ll appreciate any info you can give.
Thanks!
@orionburcham
Hi, things are going well. The initial review suggested some changes which have been done now and some additional callbacks have be implemented. Development was then put on hold in order to prioritize 5.4 bugs.
Summer months means vacation, so even though I have done mine and are working on shipping these callbacks, getting the final review done can take some time.
Hi Steen! 
It’s that time again- for me to check in and ask you about this request.
With the summer months over, any chance these callbacks might make it into 5.5?
Thanks- It’s been a while, but I understand it’s a small request that’s easily de-prioritized. I really do appreciate you adding something for it.
-Orion
@orionburcham
The 5.5 train has unfortunately left, but the feature is done just awaiting approval