- Home /
SceneAsyncLoading Game and Unity Editor Freezing (Android).
Hello there!
I've got an issue with an Android game I'm currently working on in Unity. When trying to play the game on an android phone it always freezes when loading the scene after pressing start in the main menu. When trying to start the game in the Unity Editor it does not always freeze, but most of the time. Sometimes there's no issues loading and playing the game in the Editor. I'm loading the game map and the belonging scenes one after another using a coroutine - just before it finishes, the coroutine breaks unintentionally at this "yield return null" row 65.
SetLoadingSceneText("After Clear Lists"); yield return null;
.
By now I have found out that the issue does not appear in Unity Editor at all when I switch the platform to PC, only when the platform is Android. My project is running version 2020.3.18f1, the issue only appeared recently after I switched to this version. The project was previously running on version 2019.4.11f1 without any issues, but I did edit the code in the meantime. I tried to downgrade back to the previous version (2019), but the issues persisted.
Does anyone have an idea what this issues might be caused by and how I can fix it?
Here's my coroutine to load my game scenes - I've seperated the commands for debugging.
private IEnumerator DebugLoadGame()
{
AsyncOperation loadscene = SceneManager.UnloadSceneAsync((int)SceneIndex.MainMenu);
float totalSceneProgess = 0;
float normalizedSceneProgress = 0;
SetLoadingSceneText("Unload Main Menu");
while (!loadscene.isDone)
{
totalSceneProgess += loadscene.progress;
normalizedSceneProgress = totalSceneProgess / 4f;
loadingBar.value = normalizedSceneProgress;
yield return null;
}
loadscene = SceneManager.LoadSceneAsync((int)SceneIndex.MapManager, LoadSceneMode.Additive);
SetLoadingSceneText("Load Map Manager");
while (!loadscene.isDone)
{
totalSceneProgess += loadscene.progress;
normalizedSceneProgress = totalSceneProgess / 4f;
loadingBar.value = normalizedSceneProgress;
yield return null;
}
loadscene = SceneManager.LoadSceneAsync((int)SceneIndex.UI, LoadSceneMode.Additive);
SetLoadingSceneText("Load UI");
while (!loadscene.isDone)
{
totalSceneProgess += loadscene.progress;
normalizedSceneProgress = totalSceneProgess / 4f;
loadingBar.value = normalizedSceneProgress;
yield return null;
}
loadscene = SceneManager.LoadSceneAsync((int)SceneIndex.SampleMap, LoadSceneMode.Additive);
SetLoadingSceneText("Load SampleMap");
while (!loadscene.isDone)
{
totalSceneProgess += loadscene.progress;
normalizedSceneProgress = totalSceneProgess / 4f;
loadingBar.value = normalizedSceneProgress;
yield return null;
}
Debug.Log("Init Counts: " + mapInits.Count);
foreach (GameObject item in mapObjectInit)
{
string text = "Init Scene: " + item.name;
SetLoadingSceneText(text);
IMapInit init= item.GetComponent<IMapInit>();
init.OnAllScenesLoaded();
}
if(mapInits.Count > 0)
mapInits.Clear();
if(mapObjectInit.Count > 0)
mapObjectInit.Clear();
SetLoadingSceneText("After Clear Lists");
yield return null;
SetLoadingSceneText("After wait 0.5 sec.");
sceneLoadingIsCompliedEventChannel.RaiseEvent();
SetLoadingSceneText("loading is finish");
yield return new WaitForSeconds(.2f);
loadingScreen.gameObject.SetActive(false);
}
One problem is that you do many SetLoadingSceneText() between yield, only the last one may be seen. Try replacing with Debug.Log() instead and put a Debug.Log() last in the coroutine (ln 76) to deter$$anonymous$$e if it runs to the end. Then show the log here.