- Home /
Unloaded scenes continuously keep adding?
I'm making an endless runner, and everytime the player goes out of the camera's view, the scene (which is called main2) restarts. However, for some reason, every time i stop playing mode, another scene-object is added to the hierarchy called "main2(not loaded)", and i have no idea why.
I also used a boolean to make sure it's not accidently loading the scene twice.
This is all the code im using to restart the scene:
bool hasLoaded;
private void OnBecameInvisible()
{
if(!hasLoaded)
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single);
hasLoaded = true;
}
}
Before anyone mentions it: yes, i also tried the scenemode "additive", and also tried using no scenemode at all. Both gave the same result.
Answer by OtunGroup · Sep 24, 2018 at 09:53 AM
Hi, this system calls SceneManager.LoadScene multiple times, and this creates an error. It's better to try and call this code only once. One way to do this would be by adding colliders around the perimeter of your camera, and then using OnCollisionEnter to pick up when the player has entered these new colliders. For more information, look for the error: "Overwriting the same path as another open scene is not allowed".
Hope this helps. -Greg
Your answer
![](https://koobas.hobune.stream/wayback/20220612175140im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Reload a scene without closing the inspector and hierarchy 0 Answers
When and why to put object as child of another? 2 Answers
How to move whole folder from project view to hierarchy view 0 Answers
Changes to gameObjects not being saved in hierarchy 1 Answer
Is there a problem to build the game in the Hierarchy without loading scenes at all ? 0 Answers