We have a problem loading a GameObject with a secified name from an Assetbundle created with the new SBP.
We are using:
- Unity 2018.4.20
- SBP 1.7.2
We are doing:
- Build a AssetBundle from a prefab (of simple geometry nodes) named “main”. It only contains this prefab.
- Load this Assetbundle via LoadAssetAsync with defined name “main” as input.
The problem is that asset bundles created with the old pipeline can load properly. With asset bundles that are built with SBP, our loading process no longer works.
LoadAssetAsync(“main”) doesn’t seem to work for named game objects or root objects. Maybe we are doing something wrong?
Within our loading process the assetBundleRequest.asset is null. But when I look into the result of assetBundle.LoadAllAssetsAsync() with visual studio debug, I see that there is actually an asset with the correct name.
Here our loading function:
IEnumerator LoadAssetBundleAsync(string bundlePath)
{
AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(bundlePath);
while (!assetBundleCreateRequest.isDone)
{
yield return null;
}
AssetBundle assetBundle = assetBundleCreateRequest.assetBundle;
//AssetBundleRequest assetBundleRequest = assetBundle.LoadAllAssetsAsync<GameObject>();
AssetBundleRequest assetBundleRequest = assetBundle.LoadAssetAsync<GameObject>("main");
while (!assetBundleRequest.isDone)
{
yield return null;
}
if (assetBundleRequest.asset == null)
{
Debug.Log("ERROR: Could not load main asset from Asset Bundle!");
yield break;
}
GameObject mainAssetGO = (GameObject)GameObject.Instantiate(assetBundleRequest.asset as GameObject);
}