- Home /
Build assetbundle successfully but cannot instantiate it
My unity is 5.2.0.I have built assetbundle using a simple cube and the size of the file is 45KB. And when I download it with WWW class, the www.error message shows nothing. But when I instantiate the cube, unity tells me the result is null. I assume there's something wrong in the building progress but I cannot find the reason.
SelectAsset is all the assets I selected in Project panel. I get their path one by one and put it into resourcesAssets.
for (int i = 0; i < SelectedAsset.Length; i++)
{
sourcePath = AssetDatabase.GetAssetPath(SelectedAsset[i]);
resoucesAssets[i] = sourcePath;
}
After that, I use BuildAssetBundles to build assetbundle. Do I have to use AssetBundleBuild in this condition?
BuildPipeline.BuildAssetBundles(targetPath);
Here is my downloading code. I download manifest file first, and www.error shows nothing. It's correct.
WWW www = WWW.LoadFromCacheOrDownload(mainUrl, 0);
yield return www;
AssetBundleManifest manifest = new AssetBundleManifest();
if (!string.IsNullOrEmpty(www.error))
{
print(www.error);
}
else
{
AssetBundle manifestBundle = www.assetBundle;
manifest = manifestBundle.LoadAsset("AssetBundleManifest") as AssetBundleManifest;
manifestBundle.Unload(false);
}
Then I download the assetbundle file with cube. In this case, wwwGoal.error shows nothing as well, but "Instantiate(goal);" tells me the result is null.
WWW wwwGoal = WWW.LoadFromCacheOrDownload(path + realName + extension, manifest.GetAssetBundleHash(realName + extension), 0);
yield return wwwGoal;
if (!string.IsNullOrEmpty(wwwGoal.error))
{
print(wwwGoal.error);
}
else
{
AssetBundle ab = wwwGoal.assetBundle;
GameObject goal = ab.LoadAsset(realName + extension) as GameObject;
if (goal != null)
{
Instantiate(goal);
ab.Unload(false);
}
}
The size of the assetbundle file is 45KB. It's right in normal cases. I have confused about this for several days. Could anyone tell me the reason?
Thanks!