- Home /
loading asset bundle function
I was originally hard coded in loading asset bundles and the list of asset bundles started get larger, so I want to make a function that takes in some information and loads the asset bundle for me, but for some reason on the IPhone loads the last asset bundle I feed to the function but none of the others works. On the android it never gets past
www = new WWW(string path); yield return www;
since this all works if I put all the calls in the same function I assume it has something to do with all of them being in their own StartCoroutine calls. here's the function.
private IEnumerator loadAssetBundle(string fileName, string typeName, int index)
{
if(Application.platform == RuntimePlatform.IPhonePlayer)
{
System.String strPath = "file://" + Application.dataPath + "/../assetbundles/" + fileName;
www = new WWW(strPath);
Debug.Log(strPath);
yield return www;
AssetBundleRequest request = www.assetBundle.LoadAsync(typeName, typeof(GameObject));
Debug.Log(typeName);
yield return request;
_items[index] = request.asset;
if(_items[index] == null)
Debug.Log(typeName + " has gone wrong in loading prefabs");
else
{
Debug.Log(typeName + " went fine loading prefabs");
Debug.Log(_items[(int)eItemType.OVEN_BASE].name);
}
}
else if(Application.platform == RuntimePlatform.Android)
{
System.String strPath = "jar:file://" + Application.dataPath + "!/assets/" + fileName;
www = new WWW(strPath);
Debug.Log(strPath);
yield return www;
Debug.Log(it never gets past www creation);
AssetBundleRequest request = www.assetBundle.LoadAsync(typeName, typeof(GameObject));
Debug.Log(typeName);
yield return request;
_items[index] = request.asset;
if(_items[index] == null)
Debug.Log( typeName + " has gone wrong in loading prefabs );
else
Debug.Log(typeName + " went fine loading prefabs);
}
else
{
Debug.Log("enters loadAssetBundle unity editor");
_items[index] = Resources.LoadAssetAtPath("Assets/Zombie/AstroAssets/Resources/" + typeName + ".prefab", typeof(GameObject));
}
}
and I just call it like this with the appropriate fileName, typeNames and indexes(copy and pasted from the working versions
startcouroutine(loadAssetBundle(fileName,typeName,index))
startcouroutine(loadAssetBundle(fileName,typeName,index))
startcouroutine(loadAssetBundle(fileName,typeName,index))
startcouroutine(loadAssetBundle(fileName,typeName,index))
Answer by zipper · Apr 12, 2013 at 06:43 PM
I am guessing you need something like this:
yield startcouroutine(loadAssetBundle(fileName,typeName,index))
yield startcouroutine(loadAssetBundle(fileName,typeName,index))
yield startcouroutine(loadAssetBundle(fileName,typeName,index))
startcouroutine(loadAssetBundle(fileName,typeName,index))
Your answer
![](https://koobas.hobune.stream/wayback/20220612175656im_/https://answers.unity.com/themes/thub/images/avi.jpg)