- Home /
Question by
This-is-Cole · Oct 17, 2018 at 10:09 PM ·
scene-loadingscene-switchingasyncasynchronous
AsyncOperation activating immediately even with async.allowSceneActivation = false;
Hi. Here is my code. I am trying to load another scene in the background (hence the low background loading priority to keep the gameplay uninterrupted.) However it loads the destination scene as soon as I load the first scene IN BUILDS ONLY. The editor has a temporary lag instead with makes no sense because the thread is supposed to be low priority but whatever; if it works in the build I'm happy. But it doesn't because it loads the other scene instantly. Any idea why?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class asyncLevelLoader : MonoBehaviour {
public AsyncOperation async;
public string sceneToLoad;
public bool loadIntoRam = true;
public bool loadScene = false;
void Awake(){
Application.backgroundLoadingPriority = ThreadPriority.Low;
}
void Update(){
if (loadIntoRam) {
loadIntoRam = false;
if (async == null) {
LoadIntoRam ();
}
}
if (loadScene) {
loadScene = false;
LoadScene ();
}
}
public void LoadIntoRam(){
async = Application.LoadLevelAsync (sceneToLoad);
async.allowSceneActivation = false;
}
public void LoadScene(){
async.allowSceneActivation = true;
}
}
Comment