- Home /
How to load a different scene at start of game?
I am trying to make my "Game Over" scene to be Scene 0 to make scene loading simpler, and to make it easier to add more levels after the initial completion of my project. This means my "Game Menu" will be Scene 1. Is there a way to load Scene 1 at the start of the game, but only at the start of the game?
Also, if there are any other ways to make scene loading simple and easy to scale, I'm open to new Ideas! Thanks for the help!
Why don't you simply put your Game over scene at index 1, your menu scene at index 0 and every other scene at index 2 or greater?
Answer by SuperScience · Oct 07, 2018 at 08:27 AM
I believe that Scene 0 is always the first scene to run. So even if you were to use madruytb's advice (which I think will work), you would still load scene 0 in order to load your title scene.
I'm not sure that making Game Over to be scene 0 is actually going to simplify your workflow in the long-term. It is probably beneficial to make scene 0 a company logo or asynchronous asset loading scene.
Yeah, I thought it might not be able to be easily done. Is there a way I can make it so that no matter how many levels a game has, that the scene in which the "Game Over" scene is constant?
I'm thinking of making Scene 0 a logo screen, then having it skip scene one and go to scene 2, making scene 1 the "Game Over" scene, and Scene 2 the "Game $$anonymous$$enu" scene. This way, the game will essentially start off on the menu screen, and I can load Scene 1 when they lose, and use the +1 scene script for every scene exept the logo scene.
Do you think this would work well?
Hi Aerial,
Yes you can put scenes in whatever index you want. However, from my own personal experience, I've found that it isn't beneficial to rely on scene indexes. Every once in awhile you may need to re-add a scene, so if your scenes are order-dependent, then you need to rearrange everything over-again.
Ins$$anonymous$$d, I rely on scene names. You can pass scene names as a string, and that is (at least for myself and my $$anonymous$$m) much more robust.
Scene$$anonymous$$anager.LoadScene("GameOver"); Scene$$anonymous$$anager.LoadScene("Title"); Scene$$anonymous$$anager.LoadScene("Loading"); // (etc)
Then you can build strings if you don't want to give each scene a level-name.
Scene$$anonymous$$anager.LoadScene("Level" + (currentLevelNumber + 1));
Then if you name that other scene Level10 or whatever, when you complete the level you can just go to Level11 very easily.
Does that make sense?
Answer by madruytb · Oct 07, 2018 at 04:04 AM
I never done this myself, but I guess you could:
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
In the Start function of your script thats responsible for loading levels, so if the "Game Over" scene is = 0, after executing the Start, it would jump to the Scene 1 in the build index.
It means that every time you will load the GameOver scene when the player dies or whatever, it's the menu scene that will be loaded....
That's the same solution I came up with, but ran into the same problem Hellium stated.
Your answer
Follow this Question
Related Questions
Can I use one script to toggle between scenes? 1 Answer
c# How Do I disable current script or anyother script in the program within code? 2 Answers
Can i Call Additive Scene On Network 1 Answer
The spaceship acceleration script is good ? And how to use it with engine ? 0 Answers
how i fix this? 1 Answer