- Home /
Loading screen freezes as soon as I begin loading a scene additively?
I am trying to add a loading screen while the game loads behind it. However as soon as the game begins loading the loading screen completely freezes until the game is fully loaded so it's sort of defeating the purpose.
I'm not sure where I'm going wrong. How can I load the level in while the loading screen stays animated? Any help would be much appreciated!
public class GameManager : MonoBehaviour
{
public static GameManager instance;
public bool YesNo;
float timeLeft = 5.0f;
public Text text;
private void Awake()
{
//instance = this;
//I've done this in seperate script attached to main menu
//SceneManager.LoadSceneAsync((int)SceneIndex.SUMMERS_CAULDRON);
//Title menu needs to run load game function.
YesNo = true;
//LoadGame();
}
// Start is called before the first frame update
public void LoadGame()
{
YesNo = false;
//loading level in (CAUSING FREEZE)
SceneManager.LoadSceneAsync((int)SceneIndex.SUMMERS_CAULDRON, LoadSceneMode.Additive);
Debug.Log("GAME IS LOADING");
//unloading load screen (RETURNS "SCENE TO UNLOAD INVALID")
SceneManager.UnloadSceneAsync((int)SceneIndex.MANAGER);
Debug.Log("LOADING SCREEN UNLOADED");
}
//5 second delay before level starts loading and screen freezes.
public void Update()
{
timeLeft -= Time.deltaTime;
text.text = "Time Left:" + Mathf.Round(timeLeft);
if (timeLeft < 0 && YesNo == true)
{
Debug.Log("TIME IS UP!");
YesNo = false;
LoadGame();
}
}
}
Answer by rh_galaxy · Dec 26, 2020 at 05:06 AM
It is possible to get a frame here and there to show but fully smooth loading screen while doing LoadSceneAsync is impossible. And You are not doing it right either.
Take a look at this answer. https://answers.unity.com/questions/1775650/smooth-scene-transition-issue-async-operation.html
Also this long answer here of how loading up to a point can be done async. https://answers.unity.com/questions/1786770/loading-screen-with-long-running-cpu-heavy-awake.html