I made a 3Dworld with Unity and I want save my world in a menu. I save my world with:
EditorApplication.SaveScene("Assets/Scene/name.unity",true);
And I add my new Scene to my build setting with:
var original = EditorBuildSettings.scenes;
var newSettings = new EditorBuildSettingsScene[original.Length + 1];
System.Array.Copy(original, newSettings, original.Length);
var sceneToAdd = new EditorBuildSettingsScene("Assets/Scene/name.unity", true);
newSettings[newSettings.Length - 1] = sceneToAdd;
EditorBuildSettings.scenes = newSettings;
When I load my new scene without closing the game:
Application.LoadLevel("name");
I have this error :
Level 'name' (-1) couldn't be loaded because it has not been added to the build settings.
To add a level to the build settings use the menu File->Build Settings...
When I look in my build settings, my new scene is added and checked. If I rebuild the game I can load my new scene but I don't want rebuild the game to load a new level when I just saved it.
How I can refresh my build settings without closing the game? Or how I can save my new scene more simply?
Edit : I found a alternative, I create my scene first , I add it in build settings and I erase it in the game when I save with the same name.
Add this code before
Application.LoadLevel("name");
to add it to your Build Settings: