Search Unity

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:
    84
    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

    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:
    25
    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!
     
    GB_HB likes this.
  4. Deathwing

    Deathwing

    Joined:
    May 8, 2013
    Posts:
    25
    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:
    67
    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:
    543
    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,188
    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:
    36
    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. Lucas-Hehir

    Lucas-Hehir

    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:
    18
    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:
    48
    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:
    35
    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,188
    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:
    244
    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. Lucas-Hehir

    Lucas-Hehir

    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:
    199
    This does indeed work!
     
    Lucas-Hehir and robochase like this.
  24. duartedd

    duartedd

    Joined:
    Aug 1, 2017
    Posts:
    150
    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:
    22
    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:
    5
    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:
    5
    Any update on this?
     
  31. Avijit113

    Avijit113

    Joined:
    Sep 28, 2021
    Posts:
    1
    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. Nipsey Hussle
     
  32. salandananjm

    salandananjm

    Joined:
    Mar 19, 2021
    Posts:
    9
    Any updates?
     
  33. SimonEnvisionVR

    SimonEnvisionVR

    Joined:
    Dec 13, 2020
    Posts:
    9
    Also asking for updates. I'm about to abandon addressables as it doesn't seem like it's feature complete. You can't clear the cache, you can't selectively delete downloaded assets, and if you go over the top of addressables and delete those assets anyway, there's no way for addressables to know, it assumes they're loaded and will attempt to load nothing. I think just using asset bundles directly would be easier at this point.
     
  34. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Just gonna share what we did.

    At build time, we create a json manifest containing info about the bundles we've built, then on launch and before downloading bundles, we clear up old cached bundles that are not in that manifest:
    Code (CSharp):
    1. var cachePaths = new List<string>();
    2. Caching.GetAllCachePaths(cachePaths);
    3. var cachedBundles = cachePaths.Where(Directory.Exists).SelectMany(path => Directory.EnumerateFileSystemEntries(path));
    4.  
    5. foreach (var path in cachedBundles) {
    6.     var cachedBundleName = Path.GetFileName(path);
    7.     if (!string.IsNullOrEmpty(cachedBundleName)) {
    8.         var cachedBundleVersions = new List<Hash128>();
    9.         Caching.GetCachedVersions(cachedBundleName, cachedBundleVersions);
    10.         foreach (var ver in cachedBundleVersions) {
    11.             var hash = ver.ToString();
    12.             if (!bundleHashes.Contains(hash)) {
    13.                 Caching.ClearCachedVersion(cachedBundleName, ver);
    14.             }
    15.         }
    16.     }
    17. }
    (bundleHashes is a list of hashes from our manifest json)

    Doing this, we end up with only old bundles that are still relevant, before downloading new ones
     
    igrus likes this.
  35. SimonEnvisionVR

    SimonEnvisionVR

    Joined:
    Dec 13, 2020
    Posts:
    9
    Finally figured this out to reliably remove cached file of a specific Asset Reference. Specifically a Scene.

    When you first Load a scene or addressable, you will use an AsyncOperationHandle. SAVE THAT HANDLE.

    Code (CSharp):
    1. AsyncOperationHandle<SceneInstance> loadScene;
    2. // Later...
    3. loadScene = Addressables.LoadSceneAsync(assetReference.RuntimeKey);
    4.  
    Then the full cache delete looks like this. It should be noted the asset should have been deleted / unloaded before this step.

    Code (CSharp):
    1.  public void RemoveSceneFromCache()
    2.     {
    3.        //Release the handle!!!
    4.         Addressables.Release(loadScene);
    5.        
    6.         //Do this for some reason
    7.         assetReference.ReleaseAsset();
    8.  
    9.         //Unload all your asset bundles
    10.         AssetBundle.UnloadAllAssetBundles(false);
    11.  
    12.         // This isn't needed but will clean out unused bundles.
    13.         Addressables.CleanBundleCache();
    14.  
    15.  
    16.        // Finally we can clear the cache, now that the handle, asset and bundles are all unloaded.      
    17. Addressables.ClearDependencyCacheAsync(assetReference.RuntimeKey);
    18.     }
     
  36. SimonEnvisionVR

    SimonEnvisionVR

    Joined:
    Dec 13, 2020
    Posts:
    9
    I should note that the AssetBundle.UnloadAllAssetBundles(false) will Unload every asset bundle from memory so it may unload things you didn't want it to.
     
  37. tomkail_betterup

    tomkail_betterup

    Joined:
    Nov 17, 2021
    Posts:
    106
    Would really appreciate the devs chipping in on this one!
     
  38. jtiret

    jtiret

    Joined:
    Nov 11, 2020
    Posts:
    63

    Hello @joe_nk,

    Thanks a lot for providing this code which looks very useful (didn't try it yet). I wonder whether there's an easy way to retrieve the hashes. Can't we just retrieve them by looking at the Catalog's content state file (the .bin one) which is supposed to be included in the build? But I guess you didn't find a way to extract hashes from this file at runtime which is why you had to create a custom manifest?

    Did you have to create a custom addressable build script to create your manifest? I am using Unity Cloud Build which uses the default build script, to you know an easy way to retrieve the hashes once the default build script has run?

    Thanks :)
     
  39. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    Perhaps you could do that, yes! We actually store a bit more info in our manifest, like info about the bundle size and variants of those bundles (we have a system to produce low and high res bundles and need to be able to map one to the other), which is why we create a manifest ourselves.

    In case you can't find a way to read the content state, this is a simplified (extra data excluded) version of what we use to generate the manifest in our build scripts, after the Addressables.BuildPlayerContent() process is done:

    Code (CSharp):
    1. var aaSettings = AddressableAssetSettingsDefaultObject.Settings;
    2. var aaProfileId = aaSettings.activeProfileId;
    3. var aaProfileSettings = aaSettings.profileSettings;
    4. var remoteBuildPath = aaProfileSettings.EvaluateString(
    5.     aaProfileId,
    6.     aaProfileSettings.GetValueByName(aaProfileId, AddressableAssetSettings.kRemoteBuildPath)
    7. );
    8.  
    9. var bundleHashes = new Dictionary<string, string>();
    10. foreach (var bundlePath in Directory.GetFiles(remoteBuildPath, "*.bundle")) {
    11.     var fileName = Path.GetFileNameWithoutExtension(bundlePath);
    12.     var bundleName = fileName.Substring(0, fileName.LastIndexOf('_'));
    13.     var bundleHash = fileName.Substring(fileName.LastIndexOf('_') + 1);
    14.  
    15.     if (!bundleHashes.ContainsKey(bundleName)) {
    16.         bundleHashes.Add(bundleName, bundleHash);
    17.     }
    18. }
    19.  
    20. // Write out the bundle hashes dict
    21. var bundleHashesPath = Path.Combine(Addressables.BuildPath, "bundle_hashes.json");
    22. File.WriteAllText(bundleHashesPath, JsonConvert.SerializeObject(bundleHashes));
    As you can see, we're extracting the bundle hash from the bundle file names, which take the form:
    {bundleName}_{bundleHash}.bundle
     
    jtiret likes this.
  40. jtiret

    jtiret

    Joined:
    Nov 11, 2020
    Posts:
    63
    Thanks a lot @joe_nk!

    I think I will add this in a "PreBuild" callback, which is always called after the Addressables have been built, that way I am sure these settings are included in the build :)
     
    joe_nk likes this.
  41. jtiret

    jtiret

    Joined:
    Nov 11, 2020
    Posts:
    63
    Hi @joe_nk,

    Do you store the manifest online as part of your remote bundles?
    From my understanding it looks mandatory to do that, otherwise if the manifest it just packed into the app it would progressively become outdated as you update the Catalog regularly. So you would need to:
    - Update the catalog,
    - Download the manifest (which would be referenced in the Catalog)
    - Clear caches (based on the hashes in the newly downloaded manifest, which contains hashes present in the freshly updated Catalog)
    - Finally, download any other bundle updates

    Am I right?
     
    Last edited: Jan 26, 2022
  42. joe_nk

    joe_nk

    Joined:
    Jan 6, 2017
    Posts:
    67
    We don't update remote asset bundles without a binary update, so we don't need to do that, but if you did, you'd probably want to serve the manifest from your own server
     
    jtiret likes this.
  43. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Hi all, there are versions of the ClearDependencyCacheAsync function that return operation handles (added in 1.14.0). Note that they have a second autoReleaseHandle boolean parameter. For example:
    AsyncOperationHandle<bool> ClearDependencyCacheAsync(string key, bool autoReleaseHandle)

    To clear cache entries for any bundles are no longer referenced in the currently loaded catalogs, you can use Addressables.CleanBundleCache or use the version of Addressables.UpdateCatalogs that has the autoCleanBundleCache boolean parameter enabled (added in 1.19.4).

    That being said, you can still use the UnityEngine.Caching APIs to modify the bundle cache. This is used internally by ClearDependencyCacheAsync and CleanBundleCache. The bundle cache is located in Caching.currentCacheForWriting.path.

    In regards to clearing the catalog cache, I don't think we have any APIs that can be used to access it. Theoretically it should be easier to maintain than the bundle cache since files have a timestamp in the file name (i.e. catalog_{date}.json). The catalog cache is located in {Application.persistentDataPath}/com.unity.addressables.
     
    Last edited: Feb 16, 2022
  44. chin13577

    chin13577

    Joined:
    May 8, 2017
    Posts:
    17
    I use this solution. I delete everything in Application.persistentDataPath.
    hope this helps.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using System.IO;
    4. public class ClearCacheEditor : MonoBehaviour
    5. {
    6.     [MenuItem("Tools/Cache/ClearAllCache")]
    7.     public static void ClearAllCache()
    8.     {
    9.         Debug.Log("clear cache at " + Application.persistentDataPath);
    10.         var list = Directory.GetDirectories(Application.persistentDataPath);
    11.  
    12.         foreach (var item in list)
    13.         {
    14.             Debug.Log("Delete" + " " + item);
    15.             Directory.Delete(item, true);
    16.         }
    17.  
    18.         Caching.ClearCache();
    19.     }
    20. }
    ( create this file in /Assets/Editor/ . the option will appear in Tools->Cache->ClearAllCache)
     
    Last edited: Mar 29, 2022
    fergamboa_ likes this.