Access individual assets from asset bundle once they have been downloaded

I would like to know how to access individual asset once the asset bundle has been downloaded(It Can even be asset downloaded at previous launch). I would like to access the asset as we can access the asset from resources folder.
@Adam-Buckner_1 Really appreciate any help on this
Thank you.

Thanks for the replay @DonLoquacious I am a little new to scripting. so a working script will be really nice.

Check out the manual on AssetBundles. There are script examples there.

Like i said new to scripting, I have tried the manual already. That’s why i posted it in the forum.

Then post the code you’re struggling with and we’ll help point you in the right direction. We’re not here to write scripts for you - otherwise you won’t learn anything.

There’s an entire example script in the link I provided with everything you could need.

 private IEnumerator Start()
  {
  string manifestABPath = path + "PC";

  //Loading ManifestFile
  var wwwManifest = new WWW(manifestABPath);
  yield return wwwManifest;
  AssetBundle manifestBundle = wwwManifest.assetBundle;

  //Load assetbundle Manifest Obj
  AssetBundleManifest manifest = manifestBundle.LoadAsset("PC") as AssetBundleManifest;
  manifestBundle.Unload(false);

  //Get dependent assetBundles
  string[] dependentAssetBundles = manifest.GetAllDependencies(bg);
  for (int i = 0; i < dependentAssetBundles.Length; i++)
  {
  Debug.Log(dependentAssetBundles[i]);
  }

  //Load Dependent assetBundles
  AssetBundle[] assetBundles = new AssetBundle[dependentAssetBundles.Length];

  for (int i = 0; i < dependentAssetBundles.Length; i++)
  {
  string assetBundlePath = path + dependentAssetBundles[i];

  //Get the hash
  Hash128 hash = manifest.GetAssetBundleHash(dependentAssetBundles[i]);
  var www = WWW.LoadFromCacheOrDownload(assetBundlePath, hash);
  yield return www;
  assetBundles[i] = www.assetBundle;
  }

  //Load Backgroung assetBundle
  var wwwBG = WWW.LoadFromCacheOrDownload(path + bg, manifest.GetAssetBundleHash(bg));
  yield return wwwBG;
  AssetBundle BgBundle = wwwBG.assetBundle;

  //Load Backgroung
  GameObject BGPrefab = (GameObject) BgBundle.LoadAsset("bg");
  GameObject.Instantiate(BGPrefab);

  //unload dependency assetBundle
  for (int i = 0; i < dependentAssetBundles.Length; i++)
  {
  assetBundles[i].Unload(false);
  }

  //Unload bg assetBundle
  BgBundle.Unload(false);

  }

This code does not seem to work, but this is what i have so far. Really appreciate your help.

What part doesn’t work exactly?

//Load Backgroung
GameObject BGPrefab = (GameObject) BgBundle.LoadAsset(“bg”);
GameObject.Instantiate(BGPrefab);

this part does not work. The downloaded asset doesn’t appear in the scene.

Can you explain how to use AssetBundle.LoadAsset @GroZZleR @DonLoquacious

Sure- you use it on an AssetBundle, give it the name of the asset inside (and its type IMO), and it returns the asset in question- if it exists. It’s not complicated at all.

My advice is “don’t assume that LoadAsset is the part that’s failing”. Don’t assume anything. Go through every part of the process that you’ve built and check all results for null and default values. Beyond that though, I can’t really debug what you’ve written because it has too many variables outside of the script itself. I don’t know what your assetbundle name is, what its path is, what the asset’s name is within the bundle, what type of asset it is, etc…

The entire script you wrote looks wrong to me, but I’m not sure exactly what it is that you’re trying to do with it. You’re pulling a manifest file out of an AssetBundle with LoadAsset? Are you trying to load an AssetBundle that’s bundled within another AssetBundle? What is the type of the object you’re trying to load, specifically?

The example of loading a single asset that you’ll find at the bottom of the page at http://docs.unity3d.com/Manual/LoadingAssetBundles.html is quite simple and straightforward. What is it that you need which the example isn’t providing for you? You need like 10x more debug.logs in that code you wrote- debug EVERYTHING.

The entire script i posted was something i was trying out. Here’s what i am trying to achieve, I have a asset bundle which has 20+ gameobjects. I want to download the bundle and then access only one asset at a time. I have figured out how to download the asset bundle.
But i am not able to figure out is after downloading the bundle how to access and instantiate individual objects from the storage of the mobile device.

I am Trying to load GameObject with texture from the assetbundle.

Thank you for taking time for replying.

I’ve gone through your code line by line and I can’t find a single thing wrong with it, except that as I said, I can’t verify paths and names. Check BGPrefab for null and log it. Check everything for null and lot it. Find out exactly where the sequence is failing. I can’t do that for you as I don’t have access to the assets you’re using.

when i run the game the gameobject instantiates but any texture that’s attached to it does not show up, the gameobject is in grey color

“attached” to it? That’s not how textures work. If you have the texture in your unity assets already, then you need to go into the mesh on the newly-loaded GameObject and assign the texture. If you don’t have it, then you need to import the texture separately (using LoadAsset()) and then assign it to the mesh. The GameObject originally had a REFERENCE to a texture, and that reference no longer exists.

Thanks a lot, ill check out what i can do and get back to you.

@DonLoquacious Can you tell me what bundle stands for in the following code
AssetBundleRequest request = bundle.LoadAssetAsync (“myObject”, typeof(GameObject))

I am able to get the game object to be instantiated now but still facing the issue where the gameobject is pink in color.
I am uploading the project file also can u have a look and let me know what to do.

2224887–148149–AssrtBundleTest.unitypackage (388 KB)

Bundle stands for the assetBundle that you’re trying to load the asset from. I’ve already wasted over an hour on this problem so I won’t be downloading your package, sorry. I told you that you need to load the texture onto the GameObject’s mesh- it’s the same way you always assign textures via script. Google it.

No problem. Thank you very much for your help.