- Home /
Create new scene at runtime
Is it possible to create a scene at runtime? I would like to have effectively infinite levels. My game is simply that when you reach the end of a level, another level starts and is dynamically populated with objects by script (I've got that part done!). The only thing I'm stuck on now, and is the last thing before my game is finished (YAY!) is to be able to create scene on-the-fly.
Is it possible to Instantiate(scene) or somehow duplicate a scene that's already there? I've had the thought of restarting in the current scene when the end of a level is reached, but I can't figure out how to remove all the parts and create new ones! It would be much easier for me to just create a new scene and populate it with the script that's already running (and working).
Answer by Jacebook · Mar 14, 2018 at 04:23 AM
Nevermind! Anyone else looking to do this can use the option SceneManager.CreateScene :) Just note though, it's creating a completely EMPTY scene, without even as much as a camera...
Hy @Jacebook any idea how can i add a camera in this new scene. I first created this new scene and then loaded it. Right after loading it I have this part of code
Camera camera = gameObject.AddComponent<Camera>();
Instantiate(camera, new Vector3(0, 0, 0), Quaternion.identity)
but doesn't seem to work as intented..
Your answer
![](https://koobas.hobune.stream/wayback/20220612154545im_/https://answers.unity.com/themes/thub/images/avi.jpg)