- Home /
How do I create a scene during runtime, add it to the build settings, and open it using code?
I am trying to create a game in Unity 2D. The game contains a map with many circles that can be clicked on. Clicking on each circle leads to a different scene. However, since there are thousands of circles and thousands of potential scenes, I don't want to create each scene beforehand, as that would be very time-consuming and take up lots of memory. I want to only store scenes that have been opened so far. What I am trying to do is, when a circle is clicked, generate a scene. Then, add this scene to the build settings (using code) and open the scene. Is there a way to do this during runtime only using code?
So far, I am able to create the scene, and add it to the build settings; however, when I open the build settings, the scene is present, but not checked off. The scene also appears in a grayish color instead of the black color the other scene names appear in. When I try to open the scene it gives an error message which says that 'sceneName' (-1) couldn't be loaded because it has not been added to the build settings or the AssetBundle has not been loaded.
Here is my code:
Here are the build settings with the original scene on top and the generated scene below it:
Any help with this would be greatly appreciated. Thanks!
Answer by mikaelK · Jun 06, 2020 at 10:18 PM
I know this is bit late, but I had this same problem and changing scene load to use index instead of path worked for me.
EditorSceneManager.LoadScene(yourLoadedSceneIndex, SceneMode.Single);
Your answer
Follow this Question
Related Questions
Saving and loading user made configuations 0 Answers
Display a GameOver scene then restart the game 1 Answer
SceneManager.Load is not worked in subfolders 1 Answer
Fadeout Issue 0 Answers