Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

How to clear cached addressables? Can't catch downloading error exception

Discussion in 'Addressables' started by dnnkeeper, Jul 23, 2019.

  1. dnnkeeper

    dnnkeeper

    Joined:
    Jul 7, 2013
    Posts:
    74
    I'd like to test exception handling in Packed Mode while offline. But Unity Editor is still loading cached version of my addressable scene despite logging error (but downloadOperationHandle.OperationException is null ):

    downloadOperationHandle.OperationException is still null at downloadOperationHandle.Completed event and result is cached version of my scene that loads correctly.

    So I'm having two questions: how do I clear cached addressable in editor or in build? And how do I handle 'Cannot connect to destination host' exception?

    [Addressables 1.1.5]
    [Unity 2019.2.0b7-9]
     
    Last edited: Jul 23, 2019
  2. unity_bill

    unity_bill

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    For dev testing, the easiest thing is to turn of bundle caching on your group settings. You can also write code to clear the cache manually using Unity's caching API https://docs.unity3d.com/ScriptReference/Caching.html

    Longer term, we're looking into adding some sort of Addressables.ClearCache(key) API, but don't have that yet.
     
  3. Deathwing

    Deathwing

    Joined:
    May 8, 2013
    Posts:
    8
    Hey Bill,

    can you maybe explain how we can identify and delete a cached value based from Addressables with the Caching API? I look into the cache folder, and I cant find any way to map our addressable bundles to the Caching API, also I cant find a way in the Caching API to delete a single cached entity, only to wipe them all.

    We could do a manual cached folder iteration, but for that we would need a way to identify them.

    Thanks!
     
    badgerdox likes this.
  4. Deathwing

    Deathwing

    Joined:
    May 8, 2013
    Posts:
    8
    Any...any news? :)
     
  5. Viacheslav28

    Viacheslav28

    Joined:
    Oct 17, 2019
    Posts:
    2
    Still hope for an update.... :rolleyes:
     
  6. TSI25

    TSI25

    Joined:
    Sep 22, 2013
    Posts:
    11
    This is also an issue our team is running into.
     
  7. Sam-Augmently

    Sam-Augmently

    Joined:
    Feb 7, 2020
    Posts:
    1
    Addressables 1.62 has a ClearDependencyCache method that should do the trick,
     
    davidla_unity likes this.
  8. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    51
    ClearDependencyCacheAsync is an async operation that returns void, which makes it basically useless. Internally,
    ClearDependencyCacheAsync returns AsyncOperationHandle<bool>. Can we expose the correct return type in the API, please?
     
  9. pahe

    pahe

    Joined:
    May 10, 2011
    Posts:
    502
    I'd also like to know how to clear single addressables. Removing the dependencies doesn't solve the problem in my case.
     
  10. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,085
    I'm also looking into ways of exposing Addressable Asset Group bundles to the users of my app. They should be able to see a list of all bundles downloaded and delete individual bundles from their disk. However, so far this seems difficult to implement with Addressables.
     
  11. Lukas-Labaj

    Lukas-Labaj

    Joined:
    Nov 22, 2012
    Posts:
    30
    Hi, maybe this will help. I made changes in addressable code by myself :

    Code (CSharp):
    1.  public AsyncOperationHandle<bool> ClearDependencyCacheAsync(IList<object> keys)
    2.         {
    3.             if (ShouldChainRequest)
    4.                 return ResourceManager.CreateChainOperation(ChainOperation, op => ClearDependencyCacheAsync(keys));
    5.  
    6.             foreach (var key in keys)
    7.                 ClearDependencyCacheForKey(key);
    8.  
    9.             // added by Lukas
    10.             Caching.ClearCache((int) Time.realtimeSinceStartup + 10);
    11.  
    12.             var completedOp = ResourceManager.CreateCompletedOperation(true, string.Empty);
    13.             Release(completedOp);
    14.             return completedOp;
    15.         }
    Code (CSharp):
    1. internal void ClearDependencyCacheForKey(object key)
    2.         {
    3. #if ENABLE_CACHING
    4.             IList<IResourceLocation> locations;
    5.             if (key is IResourceLocation && (key as IResourceLocation).HasDependencies)
    6.             {
    7.                 foreach (var dep in (key as IResourceLocation).Dependencies)
    8.                     Caching.ClearAllCachedVersions(Path.GetFileName(dep.InternalId));
    9.             }
    10.             else if (GetResourceLocations(key, typeof(object), out locations))
    11.             {
    12.                 foreach (var loc in locations)
    13.                 {
    14.                     if (loc.HasDependencies)
    15.                     {
    16.                         foreach(var dep in loc.Dependencies)
    17.                         {
    18.                             // added by Lukas
    19.                             AssetBundleRequestOptions options;
    20.                             if ((options = dep.Data as AssetBundleRequestOptions) != null)
    21.                             {
    22.                                 Caching.MarkAsUsed(dep.InternalId, Hash128.Parse(options.Hash));
    23.                             }
    24.  
    25.                             // original code :
    26.                             //ClearAllCachedVersions(Path.GetFileName(dep.InternalId));
    27.                         }
    28.                     }
    29.                 }
    30.             }
    31. #endif
    32.         }
     
  12. Vanilla-Plus

    Vanilla-Plus

    Joined:
    Jul 2, 2014
    Posts:
    41
    I'm loving this new caching system and the ability to easily clear it out. I just have one burning question...

    I'm working in Android, Addressables 1.10 and Unity 2020.1.0b12.

    It looks as though the remote asset cache, on Android, is stored in the apps 'Storage' folder instead of the 'Cache' folder. This seems weird to me because that's also where the content catalogue is stored. So if a user wants to clear the cached content and get some space back on their phone, currently, they'll accidentally nuke the content catalogue as well - preventing the app from being able to ever fetch those assets again later on.

    I can't seem to find any options for where the asset cache is located, either. It feels like the kind of thing that I would find in the AddressableAssetSettings file or a Groups settings, but no luck so far.

    I understand it might be possible to have your app fetch the catalogue itself from a server, but it's still worth raising I think...

    If I'm misunderstanding something really obvious... apologies!
     
    Last edited: Jun 25, 2020
  13. antonsem

    antonsem

    Joined:
    Dec 13, 2012
    Posts:
    15
    Any updates on this topic? I'm having some problems with updating ARKit scans with addressables, and I think clearing the cache will solve my problem. However, when I use
    Code (CSharp):
    1. Addressables.ClearDependencyCacheAsync("default");
    I'm getting this error:

    Exception: Attempting to use an invalid operation handle
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].get_InternalOp () (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:119)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].add_Completed (System.Action`1[T] value) (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:60)
    UnityEngine.ResourceManagement.ChainOperationTypelessDepedency`1[TObject].Execute () (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/AsyncOperations/ChainOperation.cs:105)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].InvokeExecute () (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:461)
    UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].<.ctor>b__33_0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle o) (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:113)
    DelegateList`1[T].Invoke (T res) (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.Debug:LogException(Exception)
    DelegateList`1:Invoke(AsyncOperationHandle) (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/Util/DelegateList.cs:73)
    UnityEngine.AddressableAssets.Initialization.<>c__DisplayClass14_0:<LoadContentCatalogInternal>b__0(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.ChainOperation`2:OnWrappedCompleted(AsyncOperationHandle`1)
    DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/Util/DelegateList.cs:69)
    UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.11.2/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:15)

    I'm not sure how I can use ClearDependencyCacheAsync() method, and as far as I can tell from this thread, it doesn't work anyway...
     
  14. Kultie

    Kultie

    Joined:
    Nov 14, 2018
    Posts:
    34
    No update for Addressables.ClearDependencyCacheAsync? I tried to use it with Scene's name and got error:

    Code (CSharp):
    1. Exception: Attempting to use an invalid operation handle
    2. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].get_InternalOp () (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:119)
    3. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle`1[TObject].add_Completed (System.Action`1[T] value) (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/AsyncOperations/AsyncOperationHandle.cs:60)
    4. UnityEngine.ResourceManagement.ChainOperationTypelessDepedency`1[TObject].Execute () (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/AsyncOperations/ChainOperation.cs:107)
    5. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].InvokeExecute () (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:461)
    6. UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationBase`1[TObject].<.ctor>b__33_0 (UnityEngine.ResourceManagement.AsyncOperations.AsyncOperationHandle o) (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/AsyncOperations/AsyncOperationBase.cs:112)
    7. DelegateList`1[T].Invoke (T res) (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/Util/DelegateList.cs:69)
    8. UnityEngine.Debug:LogException(Exception)
    9. DelegateList`1:Invoke(AsyncOperationHandle) (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/Util/DelegateList.cs:73)
    10. UnityEngine.AddressableAssets.Initialization.<>c__DisplayClass14_0:<LoadContentCatalogInternal>b__0(AsyncOperationHandle`1)
    11. DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/Util/DelegateList.cs:69)
    12. UnityEngine.ResourceManagement.ChainOperation`2:OnWrappedCompleted(AsyncOperationHandle`1)
    13. DelegateList`1:Invoke(AsyncOperationHandle`1) (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/Util/DelegateList.cs:69)
    14. UnityEngine.ResourceManagement.ResourceManager:Update(Single)
    15. MonoBehaviourCallbackHooks:Update() (at Library/PackageCache/com.unity.addressables@1.13.1/Runtime/ResourceManager/Util/MonoBehaviourCallbackHooks.cs:15)
    Unity 2018.4.9f1
    Addressable 1.13.1
     
    Last edited: Aug 5, 2020
  15. PascalZieglerAzuryLiving

    PascalZieglerAzuryLiving

    Joined:
    Aug 3, 2020
    Posts:
    11
    Has anybody succeeded in releasing specific bundles yet?
     
  16. Zenithin

    Zenithin

    Joined:
    Jun 7, 2016
    Posts:
    31
    Any update on this ?
    ClearDependencyCacheAsync returns void so cant really use it can we?
     
  17. cmahoneydal

    cmahoneydal

    Joined:
    Jun 2, 2020
    Posts:
    14
    Code (CSharp):
    1. public void ClearDependencyCacheForAddressable(string key)
    2. {
    3.     Addressables.ClearDependencyCacheAsync(key);
    4. }
    I haven’t been having any issues with just calling this directly, as long as I’m passing in a valid key for an addressable asset, on Verified package. Once DownloadDependenciesAsync is called, checking download size reports zero bytes. After calling clear method this against the same asset key, subsequent calls to check download size report it appropriately again.
     
  18. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,085
    The issue is that there's no clean way to know when the async process is over. It probably works to check download size every frame, but that would be a high performance-price to pay for something that could be resolved with a simple event. And it feels like an oversight since all other APIs in der Addressables system have async callback that return AsyncOperation that can be yielded in Coroutines or subscribed to an event.
     
  19. cmahoneydal

    cmahoneydal

    Joined:
    Jun 2, 2020
    Posts:
    14
    Yeah, my assumption was that the operation is quick enough pass to remove the cached bundle that the lack of a callback was intentional. I have yet to mess around with a large op to de-cache a series of items, maybe @unity_bill can shed some light on the design decision after Turkey Day haha
     
  20. cmahoneydal

    cmahoneydal

    Joined:
    Jun 2, 2020
    Posts:
    14
    Could maybe wrap a series of these calls in a custom AsyncOperation that at least provides notification that it’s complete?
     
  21. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    229
    how can I just delete all cached addressable bundles?

    on device builds, it would be handy for testing purposes to have a quick way to delete all the bundles.

    all the exposed methods require some kind of key, presumably to target a single bundle. can I just rip through all the keys somehow to clear each one individually?

    Do we have access to the folder they're cached at? maybe it's just a matter of manually doing it through System.IO?
     
    unnanego and chrismarch like this.
  22. Vanilla-Plus

    Vanilla-Plus

    Joined:
    Jul 2, 2014
    Posts:
    41
    My understanding is that bundles end up in the current Caching path, so Caching.ClearCache should work too...
     
    robochase likes this.
  23. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    167
    This does indeed work!
     
    Vanilla-Plus and robochase like this.
  24. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    126
    Anyone know of a good way to handle this when the asset bundles totally cause the app to crash until clearcache has run...Like for instance a good way to basically handle - if the app might or is gonna crash try to clear the cache or something - it might have something to do with how many times ive redownloaded one of the bundles but not sure - rather have a safety measure there in case something does occur down the line the application can try to recover.
    thoughts?
     
  25. arnaldoGaroto

    arnaldoGaroto

    Joined:
    Feb 3, 2013
    Posts:
    15
    this worked for me (cleared a cached addressable group, loaded from a test server)

    Code (CSharp):
    1. [MenuItem("Tools/clear addressables cache", false, 50)]
    2. public static void ClearAddressablesCache()
    3. {
    4.     UnityEngine.Caching.ClearCache();
    5. }
     
    kyousuke0916, alienide and Zenithin like this.
  26. caleidon

    caleidon

    Joined:
    Oct 21, 2020
    Posts:
    3
    I've tried everything to clear my cache and none of the solutions that I mentioned in this stack exchange post work.

    https://gamedev.stackexchange.com/questions/194658/how-to-clear-addressables-cache

    Additionally, I've even tried this, and still didn't work:

    Code (CSharp):
    1. if (Directory.Exists(Caching.defaultCache.path))
    2.   Directory.Delete(Caching.defaultCache.path, true);
    I load my data from YAML files at runtime, and I want to be able (while running the game) to clear the cache, re-load the addressables that should fetch new data from the YAML files (that I've changed in the meantime), so that I can use that new information in the game instantly.

    Additional note: I use all of my assets locally and never need to download anything.
     
    Last edited: Jul 15, 2021
  27. bitboy1964

    bitboy1964

    Joined:
    Oct 8, 2020
    Posts:
    2
    I have the same problem. I want to clear one single addressable out of my cache so that it will pull down from the CDN next time it's referenced, but Addressables.ClearDependencyCacheAsync() appears to just be completely non-op. It's possible I'm not passing in the right key, but I've tried the asset name, label, "default", and the asset hash.

    There is the Caching.ClearCache() solution, but that clears everything and doesn't touch the cached addressables catalog.

    I've seen this question kicking around various forums for over 2 years now... can anyone enlighten me on what I'm doing wrong and how to get this function to work?
     
  28. Vikramsingh123

    Vikramsingh123

    Joined:
    Aug 6, 2021
    Posts:
    2
  29. Vikramsingh123

    Vikramsingh123

    Joined:
    Aug 6, 2021
    Posts:
    2
    I have a similar issue. I need to clear one single addressable out of my store so it will pull down from the CDN whenever it's referred to, yet Addressables.ClearDependencyCacheAsync() appears to simply be totally non-operation. It's conceivable I'm not passing in the right key, but rather I've attempted the resource name, mark, "default", and the resource hash.
    There is the Caching.ClearCache() arrangement, yet that clears everything and doesn't contact the stored addressables list.
    I've seen this inquiry kicking around different discussions for more than 2 years now... would anyone be able to illuminate me on the thing I'm fouling up and how to get this capacity to function?
    Naruto Quotes
     
  30. caleidon

    caleidon

    Joined:
    Oct 21, 2020
    Posts:
    3
    Any update on this?
     
unityunity