I'm creating a Unity application targeting the Samsung Gear VR. I currently have two scenes:
From the first scene, I want to load the second scene in background, and switch to it once it has been loaded. While the new scene is loading in background, the user should keep the ability to move their head to see any part of the VR environment.
I'm using SceneManager.LoadSceneAsync
but it's not working:
// ...
StartCoroutiune(loadScene());
// ...
IEnumerator loadScene(){
AsyncOperation async = SceneManager.LoadAsyncScene("Scene", LoadSceneMode.Single);
async.allowSceneActivation = false;
while(async.progress < 0.9f){
progressText.text = async.progress+"";
}
while(!async.isDone){
yield return null;
}
async.allowSceneActivation = true;
}
With that code, the scene never changes.
I've tried this the typical SceneManager.LoadScene("name")
in which case the scene changes correctly after 30 seconds.
This should work
while(async.progress < 0.9f){
progressText.text = async.progress.ToString();
yield return null;
}
Secondly, I've seen cases where isDone
is never set to true, unless the scene has activated. Remove these lines:
while(!async.isDone){
yield return null;
}
On top of that, you are locking your code in that first while loop. Add a yield so the application can continue loading your code.
So your entire code looks like this:
IEnumerator loadScene(){
AsyncOperation async = SceneManager.LoadAsyncScene("Scene", LoadSceneMode.Single);
async.allowSceneActivation = false;
while(async.progress <= 0.89f){
progressText.text = async.progress.ToString();
yield return null;
}
async.allowSceneActivation = true;
}
The biggest culprit to your problem is the locking in the first while loop, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With