2
votes

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.

3
Can you explain why you need AssetBundleManifest? - Programmer
I just want to get the CRC number from the manifest to check if the assetbundle from server is the same number as the local assetbundle - Chinnawat Sirima
With AssetBundleManifest.GetAssetBundleHash? - Programmer
Yes, and also to get the Dependencies info from the manifest to resolve a problem like when the bundle's sharing the dependencies with another bundle. - Chinnawat Sirima
Did you fix this problem? - TimChang

3 Answers

1
votes

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;
}
0
votes

you should do like this

void LoadAsserBundle()
{
    AssetBundle manifestAssetBundle = AssetBundle.LoadFromFile(GetAssetBundlePath("StreamingAssets"));
    AssetBundleManifest assetBundleManifest = manifestAssetBundle.LoadAsset<AssetBundleManifest>("assetbundlemanifest");

    AssetBundle assetBundle = AssetBundle.LoadFromFile(GetAssetBundlePath("character"));
    Hash128 hash = assetBundleManifest.GetAssetBundleHash(assetBundle.name);
}
0
votes

read the following manual page at the Loading AssetBundle Manifests

Loading AssetBundle Manifests Loading AssetBundle manifests can be incredibly useful. Especially when dealing with AssetBundle dependencies.

To get a useable AssetBundleManifest object, you’ll need to load that additional AssetBundle (the one that’s named the same thing as the folder it’s in) and load an object of type AssetBundleManifest from it.

Loading the manifest itself is done exactly the same as any other Asset from an AssetBundle: AssetBundle assetBundle = AssetBundle.LoadFromFile(manifestFilePath); AssetBundleManifest manifest = assetBundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");

Now you have access to the AssetBundleManifest API calls through the manifest object from the above example. From here you can use the manifest to get information about the AssetBundles you built. This information includes dependency data, hash data, and variant data for the AssetBundles.

accordingly and from what you show above you are passing the wrong manifest file, you should pass Android asstbundle instead of what you pass.