#LoadScene issues
1 messages · Page 1 of 1 (latest)
What on earth is going on here
while (UI.globalUI == null) { }```
just an infinite loop for no reason
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();
}
}```
https://gdl.space/ifoxujagec.cs expectation vs reality
Not sure what you're asking, but your Instantiate doesn't pass in a parent, so things will end up in the hierarchy root
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
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
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();
}
Not sure what's going on, but things can become null over loadscene boundaries because Unity will unload resources.
I would advise using the debugger to check what state things are in and when they are called https://www.youtube.com/playlist?list=PLReL099Y5nRdW8KEd59B5KkGeqWFao34n
looks like solved