Downloading Asset Bundles From a Server Doesn't Save Bundles To Cache

Hi, I seem to be having trouble saving caches when downloading Asset Bundles from a Google Cloud server. From what I can see in the documentation, it seems like the caching is supposed to happen automatically? Can anyone confirm please? And if this is not the case, what is the solution please?

IEnumerator Start()
    {
        mainBundle = UnityWebRequestAssetBundle.GetAssetBundle("https://storage.googleapis.com/assetbundles_rfd/StreamingAssets");
        yield return mainBundle.SendWebRequest();

        Debug.Log(mainBundle.downloadProgress);

        if (mainBundle.result != UnityWebRequest.Result.Success)
        {
            Debug.Log(mainBundle.error);
        }
        else
        {
            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(mainBundle);

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

            //Get the AssetBundleManifest
            AssetBundleManifest loadedAssetMf = asset.asset as AssetBundleManifest;

            while (Caching.ready == false)
                yield return null;

            //Get Hash128 from the AssetBundleManifest
            var bundles = loadedAssetMf.GetAllAssetBundles();

            foreach (var v in bundles)
            {
                Hash128 tempHash128 = loadedAssetMf.GetAssetBundleHash(v);
                bundleHashes.Add(new BundleWrapper
                {
                    bundleHash = tempHash128,
                    bundleName = v
                });

                Debug.Log("Is " + v + " cached: " + Caching.IsVersionCached("https://storage.googleapis.com/assetbundles_rfd/" + v, tempHash128));
                Logger.Instance.AddLog("Is " + v + " cached: " + Caching.IsVersionCached("https://storage.googleapis.com/assetbundles_rfd/" + v, bundleHashes.Where(item => item.bundleName == v).FirstOrDefault().bundleHash));

                if (Caching.IsVersionCached("https://storage.googleapis.com/assetbundles_rfd/" + v, bundleHashes.Where(item => item.bundleName == v).FirstOrDefault().bundleHash) == false)
                {
                    otherBundles = UnityWebRequestAssetBundle.GetAssetBundle("https://storage.googleapis.com/assetbundles_rfd/" + v);

                    Debug.Log("https://storage.googleapis.com/assetbundles_rfd/" + v);
                    Logger.Instance.AddLog("https://storage.googleapis.com/assetbundles_rfd/" + v);

                    yield return otherBundles.SendWebRequest();

                    if (otherBundles.result != UnityWebRequest.Result.Success)
                    {
                        Debug.Log(otherBundles.error);
                        Logger.Instance.AddError(otherBundles.error);
                    }
                    else
                    {
                        Debug.Log("Success!");
                        Logger.Instance.AddSuccess("Success!");

                        AssetBundle otherBundle = DownloadHandlerAssetBundle.GetContent(otherBundles);
                        Instantiate(otherBundle.LoadAsset("Shrek_Model"));
                        bundle.Unload(false);
                    }
                }
            }
        }
    }

The full stack of the code is executed, and the “success!” message is called at the end once the uncached bundle has been downloaded, but then it seems that the newly downloaded bundle doesn’t ever get saved.

Any insight would be greatly appreciated, thanks!

See documentation for UnityWebRequestAssetBundle.GetAssetBundle.
You need to provide additional argument for caching to work. The overload that you use is the one that doesn’t cache.

Which argument is it I need to add please?

https://docs.unity3d.com/2022.2/Documentation/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html

Thanks, got it.

Is there a way I can get the Hash of the MAIN AssetBundle which contains the manifest for all the other bundles please? So if the device is offline, it can check if it already has the other asset bundles. Is this possible?

The documentation is deficient here. It isn’t explained how to get the correct hash128 from a downloaded AssetBundle to be saved and used in later queries. And the wording for how to use the version number argument is rather ambiguous as well and poorly explained.