Scenes are confusing the hell out of me and I'm pretty sure they should be simple to understand.
When the game loads, only the current scene has a buildIndex != -1. In order give it a 'real' build index I need to load it by path or name (because there's no build index).
The scenes are ten game scenes, one title scene and one persistent scene (which has the player and the status bar with the score etc.).
Should I load a scene every time I change scene and then load additive afterwards or should I be using Set Active Scene?
All the scenes are ticked in the Build Settings.
I'm looking at the index with this:
private void Start()
{
var sceneName = "Persistent";
var sceneBeforeLoading = SceneManager.GetSceneByName(sceneName);
Debug.Log($"Scene {sceneBeforeLoading.name}, BI = {sceneBeforeLoading.buildIndex}");
SceneManager.LoadScene(sceneName);
var sceneAfterLoading = SceneManager.GetSceneByName(sceneName);
Debug.Log($"Scene {sceneAfterLoading.name}, BI = {sceneBeforeLoading.buildIndex}");
}
Which outputs:
----------------------------------------------
Scene , BI = -1
UnityEngine.Debug:Log(Object)
Title:Start() (at Assets/Scripts/Title.cs:10)
----------------------------------------------
Scene Persistent, BI = 1
UnityEngine.Debug:Log(Object)
Title:Start() (at Assets/Scripts/Title.cs:13)
----------------------------------------------