- Home /
Getting the assets inside a bundle from unity 5 vs Unity 4
Hi folks,
I'm having an issue with reading assets from asset bundles in Unity 5, and wanted to see how others are handling this situation.
In Unity 4.x when viewing contents of asset bundles, I can get a list of all assets in the bundle (i.e. bundle.GetAllAssetNames() provides a list of asset paths inside the bundle)- I can also get this to work, when using unity 5 to view unity 4 bundles. However, in Unity 5, we only ever get the top asset (presumably the automatic 'MainAsset") . The assets themselves load fine, the issue is that, for example, when viewing a simple prefab of a game object it only lists the things we explicitly added to the bundle at bundle time. My use case- is that I simply want to put any found textures into a Texture2D list, shaders into a Shader list, etc. Again ALL of this works wonderfully in Unity 5 when viewing a Unity 4 bundle... but not when viewing a unity 5 bundle.
I have found, that if you right click the prefab, and 'select dependencies' and then use the default (from the Unity docs) assetbundle exporter script, you will get a bundle that DOES contain references to those assets (yet the bundle seems the same size so it is what I need to do via code). I have tried collecting dependencies from the selection to create this array of things to add the the bundle map... but they get added in a way that bloats the bundle.
I don't want to store a list of the assets inside the bundle, but clearly Unity 5's bundling no longer puts this info (by default) into the bundle. We do NOT use manifest files in our pipeline, so that's not the answer for me here.
At the bottom of the code sample below, are the main calls we make to make bundles (both unity 4 and unity 5)
using UnityEngine;
using System;
using System.Collections;
public class bundleIssue : MonoBehaviour
{
private WWW wwwLoader = null;
private string BundlePath = "";
void Start () {
BundlePath = "path to the bundle";
StartCoroutine(LoadAssetBundle());
}
IEnumerator LoadAssetBundle()
{
wwwLoader = new WWW(BundlePath);
yield return wwwLoader;
AssetBundle bundle = wwwLoader.assetBundle;
string[] assets = bundle.GetAllAssetNames();
int counter = 1;
foreach (string asset in assets)
{
Debug.Log(counter + ") " + asset);
counter ++;
}
}
}
// How we make bundles in Unity 5.1.4:
//BuildPipeline.BuildAssetBundles(directoryPath, buildMap, BuildAssetBundleOptions.ForceRebuildAssetBundle, target);
//
// Our Unity 4.6 way:
//BuildPipeline.BuildAssetBundle(prefab,new UnityEngine.Object[]{prefab},prefabPath,BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets,target);
Thanks for any help or ideas folks, KP