0

In unity3d I load assetbundle, but when Instantiate(bundle.mainAsset) - unity3d has a lag - some delay. This is my code, in which I load assetBundle (class DataAssetLoad - class, than contains url, nameBunle etc.)

private IEnumerator LoadCoroutine(DataAssetLoad dataAsset)
{
    while (!Caching.ready)
        yield return new WaitForEndOfFrame();

    WWW www = WWW.LoadFromCacheOrDownload(dataAsset.url, 0);

    yield return www;

    AssetBundle bundle = www.assetBundle;

    yield return new WaitForEndOfFrame();

    AssetBundleRequest request = bundle.LoadAssetAsync (dataAsset.bundleName, typeof(GameObject));

    yield return request;

    GameObject obj = request.asset as GameObject;

    GameObject newObject = Instantiate(bundle.mainAsset) as GameObject;
    newObject.transform.parent = this.transform;

    bundle.Unload(false);

    www.Dispose();
}
Knaus Irina
  • 789
  • 5
  • 15
  • 35
  • 1
    Why do you access `bundle.mainAsset` instead of `obj`? – Kay Oct 22 '15 at 12:48
  • Thank you for this hit, I repair my code. I notice than I have lag in AssetBundleRequest request = bundle.LoadAssetAsync (dataAsset.bundleName, typeof(GameObject)); – Knaus Irina Oct 22 '15 at 13:00
  • Instantiate has a cost, (and it depends of the asset) maybe you can try to do some boject pooling: http://answers.unity3d.com/questions/376129/cost-of-instantiation.html – mayo Oct 22 '15 at 17:22
  • I have model of building. I split my model by assetbundles and load its when it need. I dont`t may used pooling as I think. – Knaus Irina Oct 23 '15 at 05:48

0 Answers0