Search code examples
c#unity-game-engineassetbundle

How to get AssetBundleManifest from AssetBundle in Unity3D


I have read AssetBundles Document and also tried to get the manifest from the specific assetbundle like the document. I want to get character's manifest but the manifest from the code returns null.

I've changed the AssetBundleManifest at line 5 to character or character.manifest and it is also null:

private IEnumerator LoadAssetBundleManifest()
{
    string assetBundlePath = Application.dataPath + "/../AssetBundles/Android/character";
    AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath); // assetBundle also have data.
    var manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

    print(manifest); // manifest = null

    yield return null;
}

This image is the folder of my asset:

my assetbundle environment

PS. Now, I'm using Unity 2018.1.1f1.


Solution

  • You were close to solving it. The file you had to load in AssetBundle.LoadFromFile was the file Android, so your code would be like this:

    private IEnumerator LoadAssetBundleManifest()
    {
        string assetBundlePath = Application.dataPath + "/../AssetBundles/Android/Android";
        AssetBundle assetBundle = AssetBundle.LoadFromFile(assetBundlePath); // assetBundle also have data.
        var manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
        
        Hash128 characterHash = manifest.GetAssetBundleHash("character");
        Debug.Log(characterHash.ToString()); //hash of the character AssetBundle
        
        yield return null;
    }