2

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.

Programmer
  • 121,791
  • 22
  • 236
  • 328
Chinnawat Sirima
  • 410
  • 6
  • 10
  • Can you explain why you need AssetBundleManifest? – Programmer Jul 11 '18 at 08:19
  • 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 Jul 11 '18 at 08:23
  • With `AssetBundleManifest.GetAssetBundleHash`? – Programmer Jul 11 '18 at 08:31
  • 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 Jul 11 '18 at 08:43
  • Did you fix this problem? – TimChang Jan 20 '20 at 08:56
  • at the end. I just load the manifest and read with YAML format. The asset bundle of my project doesn't have any dependencies which mean 1 asset bundle for something that should not link to another asset bundle. so that's it. I load manifest for checking that the current version of manifest that I have is the newest version or not. if it does not then load the new manifest and also asset bundle. – Chinnawat Sirima Jun 03 '20 at 02:41

3 Answers3

3

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;
}
Jon Iturmendi
  • 51
  • 1
  • 6
0

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);
}
wei wei
  • 1
  • 1
0

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.

XRDevMK
  • 1
  • 2
  • It would be nice to move a section of the man pages into the answer here so if the link ever breaks the person can still get the gist and see code to help them out. – Carter Jul 22 '20 at 14:30