- Home /
Question by
juanfry · Nov 27, 2018 at 05:31 PM ·
assetbundledownload
Why download AssetBundle take so long?
Hello!
Why when I try to download an AssetBundle into my scene take so long?
I try to download a file from my server, a file which size is 20.1MB, and in the app the download take 19seconds. That asset is a model with materials, textures, animation and audiosource!
I understand that time is downloaded_time + imported_time into my scene?
This is my code:
using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(bundleURL))
{
www.downloadHandler = new DownloadHandlerBuffer();
//Do NOT yield the SendWebRequest function when using www.isDone
www.SendWebRequest();
while (!www.isDone)
{
progress = www.downloadProgress;
Debug.Log(progress);
downloadSlider.GetComponent<Slider>().value = progress;
progressText.GetComponent<Text>().text = (Mathf.RoundToInt(progress * 100f)).ToString() + "%";
yield return null;
}
if (www.isHttpError || www.isNetworkError)
{
Debug.Log("Error while downloading data: " + www.error);
}
else
{
downloadingDialog.SetActive(false);
Debug.Log("noerror");
// Get downloaded asset bundle
AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
foreach (string name in bundle.GetAllAssetNames())
{
Debug.Log(name);
//GameObject game = Instantiate(bundle.LoadAsset(name)) as GameObject;
AssetBundleRequest request = bundle.LoadAssetAsync(name);
yield return request;
GameObject game = Instantiate(request.asset) as GameObject;
game.transform.parent = GroundPlaneObject.transform.GetChild(0);
game.transform.localPosition = new Vector3(0, 0, 0);
game.transform.localScale = new Vector3(1, 1, 1);
game.transform.localEulerAngles = new Vector3(0, 0, 0);
model3D = game;
if (model3D.GetComponent<Animation>())
{
anim = model3D.GetComponent<Animation>();
}
if (model3D.GetComponent<AudioSource>())
{
audio = model3D.GetComponent<AudioSource>();
}
}
// Unload the AssetBundles compressed contents to conserve memory
bundle.Unload(false);
}
}
Analyzing the download with AndroidStudio: Thank you in advance! Best, Juanfran
Comment