Detecting Scene Saving/Exiting in Edit mode(right before saving/exiting from the scene at Edit time)

Hi,

I’m trying to make editing a scene as smooth as possible for my level designer, and I’d like to know if there is a way to hook into the scene saving/exiting to fix a few things before the designer leaves the scene.

In particular, I want to re-enable a few objects so that when the scene gets reloaded in the editor, I can easily use GameObject.Find to get a few references to objects before they get deactivated.

so I have 2 options:

  1. re-enabling 2 objects by name before they get saved, so that I can get their references as soon as the Awake method gets called when opening the scene.
  2. Use alternate methods to Find(name) and root.GetComponent() to also take into account disabled objects. Which, I think, could be trickier.

I can’t simply assign statically those references, because I have a persistent Singleton and references get automatically filled at the beginning of the level, on scene loading - both at runtime and edit time.

Do you know how to handle the first case?
I’d love to also know about the alternate case if possible. I know there are the “All” variants of both methods, but I don’t know if it’s efficient or how to filter out everything that is not in the scene.

Could you help me, please?

I don’t know if Unity has it or not, but in C# when we want to affect a file on loading/saving we use [OnSerializing], which lets the serializer know to use the block of code WHILE it is serializing. Also there is [OnSerialized] which does it afterwards.

My point is, if it is an option, you can add a serialization event to a Editor script attached to your objects. Alternatively, you could code a tool that lets you disable certain aspects before letting your guy go to work.

I guess that kind of serialization events only occur in the network sub engine.

I still have no solution for this unfortunately :frowning:

You could do something like this How to find an inactive game object? - Questions & Answers - Unity Discussions When the play button is press, or when a project build is triggered.