Adding Scene to build

I have a small script which adds a scene to the build. I then try to load the newly added scene but it says it hasnt been added to the build even though its in the build window and enabled. Do i have to restart the game in order for changes to take effect?

    var original = EditorBuildSettings.scenes; 

	var newSettings = new EditorBuildSettingsScene[original.Length + 1]; 

	System.Array.Copy(original, newSettings, original.Length); 

	var sceneToAdd = new EditorBuildSettingsScene("Assets/Levels/Level-3.unity", true); 

	newSettings[newSettings.Length - 1] = sceneToAdd; 

	EditorBuildSettings.scenes = newSettings;

Are you adding the scene via a custom editor menu command? If so, this should work fine.

If you are adding the scene via some script that is attached to a GameObject and only executes when you run the game, then you’re going to have problems.

In my experience trying to do something similar, I’ve found that Unity seems to load the BuildSettings from disk into memory when the game starts. And if you then change the BuildSettings at runtime, you are actually changing the settings on disk, but not in memory. So, essentially, your changed BuildSettings will be active the next time you run the game.

After messing with that for a while I finally decided that it was a much better idea to just make a custom editor menu command.

In my case I fixed it by Adding script to the scene (Created empty component and added script to it) and then in Build Settings when I clicked “Add Open Scenes” it added it.

Before I add the scene script it didn’t wont to add it. So try it