#Simple bootstrap question

1 messages · Page 1 of 1 (latest)

nocturne ridge
#

Hello everyone, I'm trying to implement my first bootstrapper. It seems to be working well except for one issue. If I hit play in the editor with only Bootstrap scene loaded it works, if I hit play with a normal scene it works. However if I have both a normal scene and the bootstrap scene open in the editor, my script does not properly detect if it is loaded. Any ideas why this is not working? Currently Debug.Log says "Bootstrap scene not loaded" even though it is in the editor and tries to load it again which causes errors. Thank you.

using System;
using UnityEngine;
using UnityEngine.SceneManagement;

namespace UnityGame
{
    public class Bootstrapper : MonoBehaviour
    {
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
        static void Init()
        {
            Application.runInBackground = true;
            string bootstrapSceneName = "Bootstrap";

            var currentScene = SceneManager.GetActiveScene();
            if (currentScene.name != bootstrapSceneName)
            {
                // if we are in any scene other than bootstrap, load bootstrap first
                SceneIndex bootstrapSceneIndex = (SceneIndex)Enum.Parse(typeof(SceneIndex), bootstrapSceneName);
                if (SceneManager.GetSceneByBuildIndex((int)bootstrapSceneIndex).isLoaded) { Debug.Log("Bootstrap scene already loaded"); }
                if (SceneManager.GetSceneByBuildIndex((int)bootstrapSceneIndex).isLoaded == false) { Debug.Log("Bootstrap scene not loaded"); }
                if (SceneManager.GetSceneByBuildIndex((int)bootstrapSceneIndex).isLoaded != true)
                {
                    SceneManager.LoadScene((int)bootstrapSceneIndex, LoadSceneMode.Additive);
                }
            }
            else
            {
                // if we are in bootstrap, load the first scene
                SceneManager.LoadScene(0, LoadSceneMode.Additive);
            }
        }
    }
}
#

Just in case you want it :

public enum SceneIndex
{
    Splash = 0,
    Bootstrap = 1,
    Loading = 2,
    Glitch = 3,
    Interference = 4,
}

and these scenes are all in the build profile / Scene List

thorn whale
nocturne ridge
#

I think I prefer my current approach if I can fix the issue with isLoaded()