AssetBundle Manager cannot get the prefab (v5.3.2)

Hi All,

I have been using the plugin “Bundle Manager” by BAxe Games until recently after upgrading Unity to v5.3.2, I am exploring the Unity AssetBundle Manager and have downloaded and played with it along with the tutorial.

However, I can download the Tank and asset cube using the tutorial scripts, but when I copied it and made my own script, it worked ONCE, but now not anymore, and I have no idea what happened and what went wrong.

Below is my script:
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using AssetBundles;

public class DLCEngine : MonoBehaviour
{
public const string AssetBundlesOutputPath = “/AssetBundles/”;
public AssetBundleLoadAssetOperation request;

private string assetBundleName = “icon_chairs”;
private string assetName = “icon_chair_239_979_g_x”;

//InitializethedownloadingurlandAssetBundleManifestobject.
protected IEnumerator Initialize()
{
//Don’tdestroythisgameObjectaswedependonittoruntheloadingscript.
DontDestroyOnLoad(gameObject);

//Withthiscode,whenin-editororusingadevelopmentbuilds:AlwaysusetheAssetBundle Server
//(Thisisverydependentontheproductionworkflowoftheproject.
//Anotherapproachwouldbetomakethisconfigurableinthestandaloneplayer.)
#if DEVELOPMENT_BUILD || UNITY_EDITOR
AssetBundleManager.SetDevelopmentAssetBundleServer ();
#else
//UsethefollowingcodeifAssetBundlesareembeddedintheprojectforexampleviaStreamingAssetsfolderetc:
AssetBundleManager.SetSourceAssetBundleURL(Application.dataPath + “/”);
//OrcustomizetheURLbasedonyourdeploymentor configuration
//AssetBundleManager.SetSourceAssetBundleURL(“http://homey-cms.cloudapp.net/test/DLC/vRay”);
#endif

//InitializeAssetBundleManifestwhichloadstheAssetBundleManifestobject.
var request = AssetBundleManager.Initialize();
if (request != null)
yield return StartCoroutine(request);
}

protected IEnumerator DownloadBundleDLC (string _bundle_name, string _asset_name, Action _action = null) where T : UnityEngine.Object
{
Debug.Log (“DLCEngine.InstantiateGameObjectAsync”);

//ThisissimplytogettheelapsedtimeforthisphaseofAssetLoading.
float _startTime = Time.realtimeSinceStartup;

//LoadassetfromassetBundle.
request = AssetBundleManager.LoadAssetAsync(_bundle_name, _asset_name, typeof(T) );

if (request == null)
yield break;

while(!request.IsDone())
yield return StartCoroutine(request);

//Gettheasset.
T _prefab = request.GetAsset ();

//Calculateanddisplaytheelapsedtime.
float _elapsedTime = Time.realtimeSinceStartup - _startTime;
Debug.Log(_asset_name + (_prefab == null ? “wasnot” : “was”)+ “loadedsuccessfullyin” + _elapsedTime + “seconds” );

if (_prefab != null) {
Debug.Log (“AssetDownloadOK”);
_action ();
} else
Debug.Log (“AssetDownloadFAIL”);
}

public IEnumerator LoadDLC(string _bundle_name, string _asset_name, Action _action = null) where T : UnityEngine.Object
{
Debug.Log (“DLCEngine.LoadDLC”);
yield return StartCoroutine(Initialize() );

//Loadasset.
yield return StartCoroutine(DownloadBundleDLC(_bundle_name, _asset_name, _action) );
}
}

I am calling the LoadDLC<T> from other scripts, but when it reaches the line if (_prefab != null), it seems the prefab cannot be retrieved and I keep getting “AssetDownloadFAIL” in log; but there is no other error being displayed, so I really don’t have a clue what’s wrong.

Thanks in advance for helping me here!

In http://homey-cms.cloudapp.net/test/DLC/vRay there is icon_chair.assetBundle but you typed “icon_chairs” in your code

I didn’t upload the bundle to that link yet, those bundles in that link are of old Bundle Manager uses. I have been testing with the Simulation Mode and also Local Server only.

Just discovered something today. I have modified the code a bit, like this:
protected IEnumerator InstantiateGameObjectAsync(string assetBundleName, string assetName)
{
// This is simply to get the elapsed time for this phase of AssetLoading.
float startTime = Time.realtimeSinceStartup;

// Load asset from assetBundle.
AssetBundleLoadAssetOperation request = AssetBundleManager.LoadAssetAsync(assetBundleName, assetName, typeof(GameObject));
if (request == null)
yield break;
yield return StartCoroutine(request);

// Get the asset.
GameObject prefab = request.GetAsset<GameObject>();

if (prefab != null)
GameObject.Instantiate(prefab);

// Calculate and display the elapsed time.
float elapsedTime = Time.realtimeSinceStartup - startTime;
Debug.Log(assetName + (prefab == null ? " was not" : " was") + " loaded successfully in " + elapsedTime + " seconds");
}

#region PUBLIC_CALLS
public void TestDownload(string _asset_name)
{
//StartCoroutine(InstantiateGameObjectAsync (assetBundleName, assetName));
StartCoroutine(InstantiateGameObjectAsync(_asset_name, _asset_name));
}

Then I tried make a GameObject prefab for it to load, then it works.
However, when I changed the to (all the bold-red parts)
I cannot get the prefab and therefore getting the “was not loaded” debug log.

Is this a limitation of current Assetbundle Manager?
That you can only load GameObject with the LoadAssetAsync but not Sprite?
Strange thing is I once got it working but now never again…

Please help! Thanks!

Hey,

Have you been able to resolve this? I am having the same problem.