- Home /
Problem loading assetbundle.
I wrote an editor script to generate assetbundles. Then I write a script to load it when running. The assetbundle file is read, but the contents does not loaded. They are found when I dump the assetbundle, however. What's wrong with my code?
This is the output by dumping the assetbundle. I just read the file and using LoadAll(), and dump then using reflection.
Obj[0]: Type: Material Name: N1110000101
Obj[1]: Type: Material Name: 1110102601A
Obj[2]: Type: Material Name: 1110102601B
Obj[3]: Type: Material Name: 1110102601C
Obj[4]: Type: AvatarPartData Name: avatarPart
Obj[5]: Type: GameObject Name: subPart
Obj[6]: Type: Transform Name: subPart
The 'Name' field is from reading 'name' property. I generate a prefab named 'subPart.prefab' and an AvatarPartData asset (inherited from ScriptableObject) as 'avatarPart.asset' during assetbundle generation.
However, when I try to check them by using Contains() or Load(), it fails.
AssetBundle ab = bundleManager.getBundle(bundleName);
if(ab.Contains("subPart")){
Debug.Log ("subPart contained!");
}
if(ab.Contains("avatarPart")){
Debug.Log ("avatarPart contained!");
}
GameObject rootObj = ab.Load("subPart", typeof(GameObject)) as GameObject;
AvatarPartData apd = ab.Load("avatarPart", typeof(AvatarPartData)) as AvatarPartData;
if(rootObj == null)
return;
Nothing logged and rootObj is null. I'm sure ab is read(isDone=true) and no error(error=null). Can anyone points out what's wrong?
Oh! I built the assetbundle using BuildPipeline.BuildAssetBundleExplicitAssetNames() instead of BuildPipeline.BuildAssetBundle() so I can specify names of assets.