1

I am newbie in AssetBundle and try to learn about this. Currently, I can load the asset from the server, but I cannot get hash from the asset file itself. It's keeping return NullException.

I have tried follow the doc here: https://docs.unity3d.com/ScriptReference/Caching.html

But still have no idea, and get the NullException at Hash too.

Found this as well and no luck: How to get AssetBundleManifest from AssetBundle in Unity3D

Then I tried follow the instruction in this post: Get Hash128 from AssetBundle for the Caching.IsVersionCached function

But still get NullException()

Here is the code I follow the latest link:

IEnumerator DownloadAssetBundle()
{
    UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle("https://www.dropbox.com/s/66psd4aphlgpo2j/testasset?dl=1");
    yield return www.SendWebRequest();

    if(www.isNetworkError || www.isHttpError) 
    {
        Debug.Log(www.error);
    }
    else 
    {
        AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);

        AssetBundleRequest asset = bundle.LoadAssetAsync<AssetBundleManifest>("assetManifestName");
        yield return asset;

        //Get the AssetBundleManifest
        AssetBundleManifest loadedAssetMf = asset.asset as AssetBundleManifest;
        //Get Hash128 from the AssetBundleManifest
        Hash128 tempHash128 = loadedAssetMf.GetAssetBundleHash("");

        //Pass to the IsVersionCached function 
        Caching.IsVersionCached("https://www.dropbox.com/s/66psd4aphlgpo2j/testasset?dl=1", tempHash128);

        //Instantiate(bundle.LoadAsset("RayBan_Sunglasses"));
    }
}

Could anyone explain how to get the Hash from assetBundle what I have done wrong?

The file name of my Asset Bundle is "testasset" If you please, specify where to put the "testasset", it would be a pleasure. Thank you so much for every answer.

derHugo
  • 83,094
  • 9
  • 75
  • 115

1 Answers1

0

the asset bundle manifest you need is stored at the platform bundle that has the same name as the folder that its inside according to this page, first you need to load the asset bundle of the platform and then you get the the asset bundle manifest object from it, from that manifest you will be able to get the hash code

private IEnumerator LoadAssetBundleManifest(string uri)
{
    using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(uri))
    {
        yield return uwr.SendWebRequest();

        if (uwr.isNetworkError || uwr.isHttpError)
        {
            Debug.Log(uwr.error);
        }
        else
        {
            // Get downloaded asset bundle
            bundleManifest = DownloadHandlerAssetBundle.GetContent(uwr);
            AssetBundleManifest testManifst = bundleManifest.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
            Debug.Log(testManifst.GetAssetBundleHash("bundlename").ToString());
        }
    }
}
XRDevMK
  • 1
  • 2