Search Unity

Can not remove assetbundle from cache right after downloading

Discussion in 'Asset Bundles' started by nilsk123, Sep 7, 2017.

  1. nilsk123

    nilsk123

    Joined:
    Dec 13, 2016
    Posts:
    19
    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?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Do you Unload() the downloaded asset bundle?
     
  3. QubixGames

    QubixGames

    Joined:
    Mar 27, 2017
    Posts:
    1
    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 :/ Is it correct behaviour?

    thnx
     
  4. Saicopate

    Saicopate

    Joined:
    Sep 25, 2017
    Posts:
    76
    Same problem here with ClearAllCachedVersions("assetBundleName") returning true but not removing the bundle from cache. Have you managed to fix this?
     
  5. RoguePrimitive

    RoguePrimitive

    Joined:
    Sep 11, 2017
    Posts:
    3
    I'm having same sort of trouble.. Anybody have fixes for this?
     
  6. Wothanar

    Wothanar

    Joined:
    Sep 2, 2016
    Posts:
    122
    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...
     
  7. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    I also can't clear cache. Even after Caching.ClearCache() and deleteting cache folder i have records in cache!
    Unity 2017.2.2p3
     
  8. KobayashiKeisuke

    KobayashiKeisuke

    Joined:
    Apr 4, 2018
    Posts:
    2
    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)
     
  9. SamuelAsherRivello

    SamuelAsherRivello

    Joined:
    Jan 16, 2011
    Posts:
    42
    Anyone find the answer to this? I'm experiencing the same issue in Unity 2017.3.1p1.
     
  10. jmeineke

    jmeineke

    Joined:
    Feb 23, 2018
    Posts:
    1
    Problem also exists in Unity2018.1.02f. Would love to hear from Unity on this...
     
  11. Wuna

    Wuna

    Joined:
    Nov 4, 2015
    Posts:
    7
    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
     
  12. DesarrolloBGD

    DesarrolloBGD

    Joined:
    Dec 12, 2017
    Posts:
    1
    Same issue in Unity 2018.2.3f1

    Code (CSharp):
    1.  
    2. private IEnumerator LoadFromCacheOrDownloadBundle(string bundleName, int bundleVersion, bool unloadAfterLoad)
    3.         {
    4.             string url = BundlesConfig.GetPath() + "/" + bundleName;
    5.  
    6.             WWW download = WWW.LoadFromCacheOrDownload(url, bundleVersion);
    7.  
    8.             while (!download.isDone)
    9.             {
    10.                 DownloadProgress = Mathf.Clamp01 (download.progress);
    11.                 DownloadProgressUpdated?.Invoke(bundleName, download.progress);
    12.                 yield return null;
    13.             }
    14.  
    15.             if (!string.IsNullOrEmpty(download.error))
    16.             {
    17.                 PopupManager.Instance.QueuePopup(assetBundleDownloadFailPopup);
    18.                 Debug.Log(download.error + ", Request URL " + url);
    19.                 yield break;
    20.             }
    21.             else
    22.             {
    23.                 AssetBundle myLoadedAssetBundle = download.assetBundle;
    24.  
    25.                 GameObject[] assetLoadRequest = new GameObject[] { };
    26.                
    27.                 assetLoadRequest = myLoadedAssetBundle.LoadAllAssets<GameObject>();
    28.                 yield return assetLoadRequest;
    29.                 lastAssetsLoaded = assetLoadRequest;
    30.  
    31.                 if (unloadAfterLoad)
    32.                     myLoadedAssetBundle.Unload(false);
    33.  
    34.                 download.Dispose();
    35.             }
    36.         }
    37.  
     
  13. IQpierce

    IQpierce

    Joined:
    Jan 24, 2011
    Posts:
    43
    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.
     
  14. aemobile_zq

    aemobile_zq

    Joined:
    Mar 29, 2016
    Posts:
    6
    no. not fixed...
     
  15. JonBFS

    JonBFS

    Joined:
    Feb 25, 2019
    Posts:
    39
    Bump, same problem. can't find solution anywhere
     
  16. devon_b

    devon_b

    Joined:
    Aug 2, 2018
    Posts:
    9
    Bump, still broken.
     
  17. francoclivemaleke23

    francoclivemaleke23

    Joined:
    Jun 28, 2019
    Posts:
    1
    same here
     
    devon_b likes this.
  18. antifuzz

    antifuzz

    Joined:
    Feb 22, 2013
    Posts:
    99
    same here
     
  19. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    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?
     
  20. pesseba

    pesseba

    Joined:
    Aug 14, 2008
    Posts:
    13
    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:

    Code (CSharp):
    1.  
    2.                 Uri uri = new Uri(my_url);
    3.                 string bundle_name = System.IO.Path.GetFileNameWithoutExtension(uri.AbsolutePath);
    4.                 bool isCaching = Caching.ClearAllCachedVersions(bundle_name);
     
    akhror_unity and spaceowlpro like this.
  21. spaceowlpro

    spaceowlpro

    Joined:
    Nov 8, 2017
    Posts:
    12
    You're awesome! This was exactly what I couldn't figure out myself. Thank you!!!