- Home /
Loading Bar in Different Scenes
Hello, I have a pretty simple loading bar currently in a main menu scene.
IEnumerator LoadingScreen(string sceneName)
{
loadingScreenObj.SetActive(true);
aSync = SceneManager.LoadSceneAsync(sceneName);
aSync.allowSceneActivation = false;
while (!aSync.isDone)
{
loadSlider.value = aSync.progress;
if(aSync.progress == 0.9f)
{
loadSlider.value = 1f;
aSync.allowSceneActivation = true;
}
yield return null;
}
}
This is all fine and dandy, and works well enough (I followed a tutorial to get the effect). The problem is that the game scene that it loads into has an Awake() function that takes about 20 seconds to get through because it generates land and initializes a lot of scripts.
After a bit of research, I'm still confused. How do I get it so that the loading bar in the main menu includes this awake function in the game scene? Can I make it so that Text in the UI of the main menu scene changes based on the part of the super long awake function?
Is any of this even possible?
Answer by Jack-Mariani · May 15, 2019 at 07:18 AM
Can I make it so that Text in the UI of the main menu scene changes based on the part of the super long awake function?
Alas if the board creation is in another scene there's no way to attach the behaviour to the scene load progress.
SOLUTION 1 - GENERATE THE BOARD IN LOADING SCENE
The best solution I see is to create the board in the load scene, with a script set as DontDestroyOnLoad. So you create the board in the loading scene itself and you pass it to the next scene. You can keep this generation "invisible" by setting the gameobject disabled, then you enable it in the next scene.
So you create the board in the loading scene and use a coroutine to track its progress (then you connect the board creation progress with the scene load progress).
SOLUTION 2 - LOAD THE SCENE AS ADDITIVE
Another option is that you may load the game scene with LoadSceneMode.Additive. But you will need anyway to track the progress of the generation, so I think the first option is better suited.
Your answer
Follow this Question
Related Questions
Loading Bar for Awake Function 1 Answer
Got a problem with Async! 0 Answers
Load level async freezing animation for several seconds 0 Answers
Do I need a Loading Screen? 1 Answer
LoadSceneAsync additive and moving scene root problem 1 Answer