- Home /
Load specific scene in editor
Is there a way that you can load / unload a scene from the editor script? I want to automate a task of ensuring a set of scenes are constructed correctly, but I can't find any API calls for doing a modify - save - load sequence in the editor.
Ideally, I'd do something like:
foreach(var scene in myLevels) { //Save any changes in currently loaded scene //Load the scene //Find objects I want to configure and modify them }
Is this possible to automate?
Answer by Steven-Walker · Oct 14, 2011 at 06:24 PM
EditorApplication.SaveCurrentSceneIfUserWantsTo(); EditorApplication.OpenScene(scenePath);
Answer by Verusoft · Jan 06, 2016 at 11:30 AM
EditorApplication.SaveCurrentSceneIfUserWantsTo(); and EditorApplication.OpenScene(scenePath); are obsolete!
You should use EditorSceneManager. For example:
 using UnityEngine;
 using UnityEditor;
 using UnityEditor.SceneManagement;
     
 public class MySceneLoader : MonoBehaviour {
 
     [MenuItem ("Scenes/Open Main Scene")]
     static void OpenMainScene() {
         EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
         EditorSceneManager.OpenScene("Assets/Scenes/main.unity");
     }
 }
Don't forget to put MySceneLoader.cs into Editor folder.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                