I want to delete some gameobjects OnSavingScene,but recover them OnSavedScene.
I know that EditorSceneManager.sceneSaved and EditorSceneManager.sceneSaving is the very time to do it, but I can’t reference to these gameobjects ,because when I copy them and destory them on EditorSceneManager.sceneSaving ., the reference will be null.So, on EditorSceneManager.sceneSaved,I can’t instantiate them . I think that some function like ctrl+c → ctrl +v will help ,but have no idea to do it.Does anyone have some suggestion for this issue?
ctrl+d creates a duplicate, then you move it where you want.
You could try to actually ctrl+c/ctrl+v:
// copy
Selection.objects = yourGameObjects;
EditorApplication.ExecuteMenuItem("Edit/Copy");
// paste
EditorApplication.ExecuteMenuItem("Edit/Paste");
I haven’t tried it myself, though.
An alternative is to set the hide flags to DontSave in sceneSaving, and then set them back again to None in sceneSaved.
Oh,thanks a lot. Hide flags seem to be a more smart method.