I have an issue with a level loader I’ve written where the following code is not completing:
IEnumerator LoadAsync(int i) {
Debug.Log ("Loading...");
aop = Application.LoadLevelAsync(i);
aop.allowSceneActivation = false;
Debug.Log ("Post-LLA");
yield return aop;
Debug.Log ("Load done time: " + Time.time);
loading = false;
levelReady = true;
yield return new WaitForSeconds(1f);
//aop.allowSceneActivation = true; (this happens in the Ready function)
Ready ();
}
The aop variable is defined as an AsyncOperation. Some background here, I had another yield return new WaitForSeconds(1f) line preceding the yield return aop line, and it would hang on that as well. I get the debug output in the console before any yields. I’d originally started writing this as a problem with LoadLevelAsync/AdditiveAsync, but then discovered none of the yield calls were getting through. I’ve tried calling with both StartCoroutine(LoadAsync(i)) and (“LoadAsync”, i) just to make sure there wasn’t some odd change I missed.
It is being called from this function on an object tagged for DontDestroyOnLoad():
public void LoadLevel (int i) {
loading = true; levelReady = false;
Application.LoadLevel("Loading");
PercentageID pid = FindObjectOfType<PercentageID>();
if (pid != null) percentageText = pid.GetComponent<Text>();
loadContent = GameObject.Find ("LoadingContent");
Debug.Log ("Load start time: " + Time.time);
StartCoroutine ("LoadAsync", i);
}
Any ideas on what’s happening? Is this a bug with the latest versions of Unity? (I was on 5.0.1 originally and now the current 5.0.2)