#LoadScene issues

1 messages · Page 1 of 1 (latest)

unique ember
#

What on earth is going on here

while (UI.globalUI == null) {  }```
#

just an infinite loop for no reason

shut birch
#
        LoadScene(1);
        while (UI.globalUI == null) { }
        scene.Load();
    }

    public void LoadScene(int sceneId) {
        loadingScene.SetActive(true);
        StartCoroutine(LoadSceneAsync(sceneId));   
    }

    

    IEnumerator LoadSceneAsync(int sceneId) {
        Loaded = false;
        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneId);
        while (!operation.isDone) {
            fillImage.fillAmount = Mathf.Clamp01(operation.progress / 0.9f);
            yield return null;
        }
        Loaded = true;
    }
public class GameSetup {
    public Unit[] units;

    public static LoadingScreen  screen;

    public static void SetupGame(GameObject terrain, UnitPreset[] allies, UnitPreset[] enemy) {
        UI.controlUnits.Clear();
        UI.aliveAlly = 0;
        UnityEngine.Object.Instantiate(terrain);
        foreach (UnitPreset unit in allies) {
            unit.Summon(Team.TEAM_ALLY);
        }
        foreach (UnitPreset unit in enemy) {
            unit.Summon(Team.TEAM_ENEMY);
        }
    }

    public static void LeaveToMenu() {
        screen.LoadScene(0);
    }
}
public abstract class Scenario{
    public abstract UnitPreset[] allies { get; }
    public abstract UnitPreset[] enemy { get; }
    public abstract GameObject terrain { get; }

    public virtual void OnLoad() { }

    public virtual void Load() {
        GameSetup.SetupGame(terrain, allies, enemy);
    }
}
public class UI : MonoBehaviour{
public static UI globalUI = null;

private void Awake() {
        globalUI = this;
    }

    private void Start(){
        actionBar.globalUI = this;
        ProjectileManager.projectileContainer = projectileContainer;
        //new Scenario().Load();
    }
}```
unique ember
#

Not sure what you're asking, but your Instantiate doesn't pass in a parent, so things will end up in the hierarchy root

shut birch
#

when i put new Scenario().Load() in Start() of UI scene is loaded correctly, but if i put it after while(), it loads scenario before scene

unique ember
#

while (UI.globalUI == null) { } is nonsense code and will do nothing except potentially create an infinite loop

#

You would need to move your Load code to the end of a coroutine, like one that waits for Loaded to be true

shut birch
#

ends up loading nothing...

IEnumerator LoadSceneAsync(int sceneId) {
        Loaded = false;
        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneId);
        while (!operation.isDone) {
            fillImage.fillAmount = Mathf.Clamp01(operation.progress / 0.9f);
            yield return null;
        }
        Loaded = true;
        scen.Load();
    }
unique ember
shut birch
#

looks like solved