How to async load new Scene and Resources simultaneously?

I need some help on how to properly load resources at scene transitioning without noticing any lag.
I searched the web for this, but it seems there are only answers of asyncronous loading just the desired scene.


My game is constructed by having a menu scene (=current scene) and a game scene (=target scene).


From the menu I can select a particular level. Each level is a prefab, which should get loaded into the game scene.


The prefab-loading should be part of the scene transitioning procedure as loading afterwards makes no sense. The application should load the prefab after the target scene is loaded (async.progress >= 0.9f) and after both are loaded the scene should activated.

This is what I have, but it will loop forever because allowSceneActivation = true is never reached.

private IEnumerator LoadScene(string level, string prefab = ""){
	float loadcount = prefab == "" ? 1f : 2f;

	AsyncOperation async = SceneManager.LoadSceneAsync(level);
	async.allowSceneActivation = false;

	ResourceRequest prefabRequest = Resources.LoadAsync(prefab );
	DontDestroyOnLoad (Instantiate (prefabRequest.asset as GameObject));

	while (async.progress < 0.9f) {
		loadProgress = (async.progress) / loadcount * 0.9f;
		progressBar.value = loadProgress;
		yield return null;
    if(prefabRequest != null){
	    while (!prefabRequest.isDone) {
		    loadProgress = (async.progress + prefabRequest.progress) / loadcount * 0.9f;
		    progressBar.value = loadProgress;
		    yield return null;
     async.allowSceneActivation = true;

这一句“ async.allowSceneActivation = false; ” 会导致下一句:“ ResourceRequest prefabRequest = Resources.LoadAsync(prefab );” 永远加载不出来,这是Unity 内部的逻辑限制的。

When allowSceneActivation is set to true isDone can complete. While isDone is false, the AsyncOperation queue is stalled
很不幸,这个 queue 估计就只有一个。

I have never used Resources.LoadAsync() so I wouldn’t know about that, can it be loading while you have a LoadSceneAsync() in progress?

I could post how I do it but it is very similar to how you do. But I’m sorry to say it, there will be lagging, because it isn’t fully async. Also you need to allow the scene to start after 90% which you have noticed. That will run all the Start() methods of your objects and if they take longer than a frame the game will appear to freeze. A trick I use is to set Time.timeScale = 0, and continue the loading of my level in Update() for however many loops I need, and when done I set Time.timeScale = 1.

in unity you can only have one async load operation at a time
i’m not joking
and you cannot start another load request until the scene is activated
i’m not even making that up

once you fix your code to follow these 2 rules you can change how much cpu load eats up by changing priority