AssetBundle.LoadAsync is freezing the game during loading

Hi,
I’m trying to stream some prefabs in my scene without freeze time due to the loading, and it’s why i took a look on the AssetBundle Asyncronous loading, but even with AssetBundle.LoadAsync the game is still freezing during the loading time. (it is indeed in the loading time, not when i displays the prefab on the scene, who make a lag too, but this one is normal), i also tried to print the “progress” time, but it is displaying always “0” during only 1frame…

here is a screen of my profiler when the object load asyncronously (and is not displayed yet) it is taking 99% of the CPU, is it normal ?

I’m actually out of solution and don’t know what i have done wrong in my script, i past it below for you to take a look, maybe you will be able to make me learn from my mistakes:

public class TestStreaming : MonoBehaviour 
{
	private string 				url;
	private WWW 				www;
	private AssetBundle 		bundle;
	private GameObject			Scene;
	private AssetBundleRequest 	ObjectToLoad;

	// Use this for initialization
	
	IEnumerator Start() 
	{
		this.url = "file://" + Application.dataPath + "/Bundle2.unity3d ";
		this.www = WWW.LoadFromCacheOrDownload(url,1);
		yield return www;
		this.bundle = www.assetBundle;
	}
	
	void Update()
	{
		if(Input.GetKeyDown(KeyCode.E)) //when pressing "e" the gameobject is loading
			StartCoroutine("Loading");
		
		if(Input.GetKeyDown(KeyCode.R)) //when pressing "r" i display the loaded gameobject
		{
			if(ObjectToLoad.isDone)
			{
				Instantiate(ObjectToLoad.asset as GameObject);
				bundle.Unload(false);
			}
		}
	}
	
	
	IEnumerator Loading() 
	{
		this.ObjectToLoad = bundle.LoadAsync("Prefab2Test", typeof(GameObject)); //here i'm loading the gameobject asyncronously
		
		while (!ObjectToLoad.isDone) 
		{
			print(ObjectToLoad.progress * 100f); //and displaying the progress time
        	yield return ObjectToLoad;
    	}
	}
	

}

In hope you will be able to guide me, thank you for your help :slight_smile:

Well, at least your progress update will only run once since yield return ObjectToLoad; will wait until the full loadasync is done.

–

1 Answer

1

Hey did you solve he problem, I have the same issue