Can not remove assetbundle from cache right after downloading

We’re using Unity 2017.1.0f3 to download assetbundles from our server and store them in cache. To do so we use the UnityWebRequest class and its appropriat assetbundledownloadhandler.

When a download is finished, the assetbundle isnt stored anywhere other than the caching system, we do not put it in a list the way the assetbundlemanager does by default. Therefor in theory there should be no reference to it in memory. When the unitywebrequest is finished we call dispose on it, and we have the disposedownloadhandlerondispose set to true.

However, when we call clearallcachedversions for an assetbundle that was download in the same app run, we get a warning ‘assetbundle with hash xxxx still in use’, the only way to remove it is by restarting the app.

How come it’s still being referenced somewhere?

Do you Unload() the downloaded asset bundle?

Hi, we have similar problem with ClearAllCachedVersions. There is no warning about usage of bundle, because it is unloaded, and ClearAllCachedVersions(“ourBundleName”) returns true, but bundle is not removed from file system :confused: Is it correct behaviour?

thnx

Same problem here with ClearAllCachedVersions(“assetBundleName”) returning true but not removing the bundle from cache. Have you managed to fix this?

I’m having same sort of trouble… Anybody have fixes for this?

same here and im getting isane the maps load from a old version and the textures looks ugly and i cant load the new changes coz they are seems to be taking always a old version, i clean from locallow the files and do the clear code and sum a new num version but still cant see the changes ive done something its missed or weird here…

I also can’t clear cache. Even after Caching.ClearCache() and deleteting cache folder i have records in cache!
Unity 2017.2.2p3

I have same trouble in Unity2017.4.2f2 and Unity2018.1.0f2

After I load AssetBundle, I call “Caching.ClearCache”, it return false because the asset is not unloaded.
Then, I also call “Caching.ClearAllCachedVersions”, it return true despite asset is not unloaded yet.
Furthermore, “Caching.ClearCacheVersion” also returns true despite asset is not unloaded yet.

After I unload that assetbundle, i tried call “Caching.ClearAllCachedVersions” and “Caching.ClearCacheVersion”.
but both APIs return true and don’t remove cache.

Only when I call “Caching.ClearCache” and it succeeded, both API ( “Caching.ClearAllCachedVersions” and “Caching.ClearCacheVersion” ) return false.

Are there API are implemented correctly ?
I wonder these API seem not to be implemented “remove cache”.

( Caching.IsVersionCached works correctly, so i use it for check behaviour)

Anyone find the answer to this? I’m experiencing the same issue in Unity 2017.3.1p1.

Problem also exists in Unity2018.1.02f. Would love to hear from Unity on this…

I also encountered this problem
it seems that the directory wasn’t refreshed after it was manipulated so Caching handled it as if it was still there even though it isnt, same goes to Caching.IsVersionCached where it will return false when the app start, so i had to always redownload the bundle before it will return true even though it had been downloaded in the previous session of the game

Same issue in Unity 2018.2.3f1

private IEnumerator LoadFromCacheOrDownloadBundle(string bundleName, int bundleVersion, bool unloadAfterLoad)
        {
            string url = BundlesConfig.GetPath() + "/" + bundleName;

            WWW download = WWW.LoadFromCacheOrDownload(url, bundleVersion);

            while (!download.isDone)
            {
                DownloadProgress = Mathf.Clamp01 (download.progress);
                DownloadProgressUpdated?.Invoke(bundleName, download.progress);
                yield return null;
            }

            if (!string.IsNullOrEmpty(download.error))
            {
                PopupManager.Instance.QueuePopup(assetBundleDownloadFailPopup);
                Debug.Log(download.error + ", Request URL " + url);
                yield break;
            }
            else
            {
                AssetBundle myLoadedAssetBundle = download.assetBundle;

                GameObject[] assetLoadRequest = new GameObject[] { };
               
                assetLoadRequest = myLoadedAssetBundle.LoadAllAssets<GameObject>();
                yield return assetLoadRequest;
                lastAssetsLoaded = assetLoadRequest;

                if (unloadAfterLoad)
                    myLoadedAssetBundle.Unload(false);

                download.Dispose();
            }
        }

Was this error fixed? My team is considering upgrading to 2018.2.17f1 - we use a similar pattern (downloading the bundle, immediately unloading, then loading it later from the cache if needed) and we’re concerned that this upgrade could break our mission-critical bundles content system.

no. not fixed…

Bump, same problem. can’t find solution anywhere

Bump, still broken.

same here

1 Like

same here

The forums are for help / assistance and don’t guarantee a Unity Dev reply. That being said, I’ve yet to see a FogBug come through about this issue. Has anyone reported this issue with an attached repro project yet? If so what is the case number?

I got the same problem here with Unity 2018.3.7f1, and found a solution. The problem I found is because unity cache is saved in a folder with the “file name” and not with “bundle name”. So, the file name and the bundle name is not necessarily the same. The code below solved my problem:

                Uri uri = new Uri(my_url);
                string bundle_name = System.IO.Path.GetFileNameWithoutExtension(uri.AbsolutePath);
                bool isCaching = Caching.ClearAllCachedVersions(bundle_name);
2 Likes