Quantcast
Channel: Latest Questions on Unity Answers
Viewing all articles
Browse latest Browse all 171066

Does coroutine block the script's thread at loadLevelAdditiveAsync?

$
0
0
Hello guys: I met a loading problem, i used a coroutine to load the scene in back ground ,but the current script 'update function was blocked... what i want to do is to use a loadingscene to load the main scene, the loading scene code is //loadingScene.cs void onEnter () { StartCoroutine(LoadMainScene()); } IEnumerator LoadMainScene() { load = Application.LoadLevelAdditiveAsync ("MainScene"); yield return load; Debug.Log("load.isDone:" + load.isDone); } void FixedUpdate() { this.updatePercent (); } void Update () { Debug.Log("Loading Scene updating...\n"); } //In MainScene.cs which is link to MainScence.unity void Awake () { Debug.Log("MainScene::Awake(), begin TimeStamp :" + System.DateTime.Now); StartCoroutine(InitResouce()); Debug.Log("MainMediator::Awake(), end TimeStamp :" + System.DateTime.Now); } //this coroutine will block LoadingScene.cs's update... can't get the loading progress.... lead to loading hiccups IEnumerator InitResource() { // do many GameObject.Instantiate(prefabs) as ...; yield return 0; Debug.Log("Start finished!"); } the result is like : Loading Scene updating...loading progress:0 Loading Scene updating...loading progress:0.1316038 MainScene::Awake(), begin TimeStamp :09/06/2013 16:51:33 MainScene::Awake(), end TimeStamp :09/06/2013 16:51:35 Loading Scene updating...loading progress:1 the progress is from 0 to 0.13 then directly to 1.... it's not smooth at all.. the InitResource function will cost 2 seconds , and the loading progress bar will stop 2 seconds to wait.. I used a coroutine to do this task.. why it still block the Loadingscene.cs script.. Do you guys meet this kinds of problem before? Any advices will be appreciate.. thanks

Viewing all articles
Browse latest Browse all 171066

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>