I have about 10 scenes in my project. Scene switching is done using buildIndexes. How do I change the startup scene without having to rewrite all of my scene switching code ? (since changing the scene hierarchy would shift all scene indexes by one… I know that I could make some calculations to account for that but is that really necessary ?)
The startup scene is always scene 0. Nothing you can do about that. Loading scenes by name is much easier - you don’t have to look in the build index to change level correctly.
Actually, don’t every use build indexes for anything. They’re incredibly brittle.
SceneManager.GetActiveScene().whateverYouWantToGet;
//- > variables are there for you including name, id, all you need.
What I did for my game, that a lot of people don’t prefer, is I created my own global non-destructible game object with a script that manages scene data. That way you can also make that global object’s script hold the game menus, player data and display and manage saving and loading screens.
You’re managing then global and local data, the global data is managed by the persistent main game object, and the local data includes scene scripts.
It can take a while to set up, but if you can get scene ping pong going so to speak you’ve gotten pretty far.