Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[1.5.0] Proper way of using Addressables.CheckForCatalogUpdates()

Discussion in 'Addressables' started by carlbinalla, Jan 7, 2020.

  1. carlbinalla

    carlbinalla

    Joined:
    Mar 5, 2018
    Posts:
    7
    Using Unity 2019.2.13f1

    How to exactly use
    Addressables.CheckForCatalogUpdates()
    ?

    Here's how I did it:

    Code (CSharp):
    1. void Start()
    2. {
    3.     var aw = Addressables.CheckForCatalogUpdates(false);
    4.     aw.Completed += OnCompletedCheck;
    5. }
    6.  
    7. private void OnCompletedCheck(AsyncOperationHandle<List<string>> obj)
    8. {
    9.     var catalogList = obj.Result;
    10.     Debug.Log("CATALOG COUNT - " + catalogList.Count);
    11. }
    I run this every time I update a previous build, and uploading the updated bundle and catalog. The problem is, the count always return 0, meaning there are no updatable catalog.

    Reading the documentation, what I understood that this works with static contents, so I also tried building a group with static contents, then changed some of it, checked for update restriction then applied. It still returns 0.

    Although the assets are updated with the remote asset when running the app, the problem is I don't know if I should prompt a update or prompt a download for the asset. I know how to check if an asset is already cached or needs to be downloaded, but not how to check if the asset is cached, but there is a new update.

    UPDATE:

    It seems that using
    Addressables.ClearDependencyCacheAsync(key)
    can clear the cached asset, so I used it like this:

    Code (CSharp):
    1. void Start()
    2. {
    3.     Addressables.GetDownloadSizeAsync(key).Completed += GetSizeDone;
    4. }
    5.  
    6. void GetSizeDone(AsyncOperationHandle<long> obj)
    7. {
    8.     long fileSize = obj.Result;
    9.     if (fileSize == 0)
    10.         //Asset is cached and no update
    11.     else
    12.     {
    13.         //Asset is new or cached asset has update, can't say. So I need to clear the old cache first
    14.         Addressables.ClearDependencyCacheAsync(obj);
    15.         Addressables.ClearDependencyCacheAsync(key);
    16.         // used the handle and the asset name just to be sure
    17.     }
    18.     Addressables.Release(obj);
    19. }
    I was expecting that the even before I download the new update/asset, the old cached asset has already been cleared, but when I checked the size, it didn't decreased at all.

    This means that
    Addressables.ClearDependencyCacheAsync(key)
    only clears whatever the current catalog' assets points to, like if you download the new/updated asset, then call the method, it will be cleared. But if it checks that there is a new asset/update and called the method, the old asset will not be cleared
     
    Last edited: Jan 20, 2020
  2. Atlantiss

    Atlantiss

    Joined:
    Aug 5, 2018
    Posts:
    14
    [/QUOTE]
    How did you check if the asset is already cached?
     
  3. carlbinalla

    carlbinalla

    Joined:
    Mar 5, 2018
    Posts:
    7
    Something like this:

    Code (CSharp):
    1. void Start()
    2. {
    3.     var sceneAsset = Addressables.GetDownloadSizeAsync(sceneName);
    4.     sceneAsset.Completed += GetSizeDone;
    5. }
    6. private void GetSizeDone(AsyncOperationHandle<long> obj)
    7. {
    8.     long fileSize = obj.Result;
    9.     if(fileSize == 0) {
    10.         Debug.Log("Cached");
    11.     } else {
    12.         Debug.Log("Needs to be downloaded");
    13.     }
    14. }
     
    Atlantiss likes this.
  4. Atlantiss

    Atlantiss

    Joined:
    Aug 5, 2018
    Posts:
    14
    Thanks ill try this
     
  5. carlbinalla

    carlbinalla

    Joined:
    Mar 5, 2018
    Posts:
    7
    Anyone tried Addressables.CheckForCatalogUpdates()? Or at least a way to check if the asset is an update of the current cached asset
     
  6. lettablet

    lettablet

    Joined:
    Jan 11, 2020
    Posts:
    2
    I am getting 0 count for catalog updates whatever I do. Any news?
     
  7. carlbinalla

    carlbinalla

    Joined:
    Mar 5, 2018
    Posts:
    7
    Can anyone tag any Unity Devs here? A sample code for overwriting cached assets or checking if there is an update will be very helpful for users of Addressable Assets.

    As of now, every time I update a addressable scene, instead of overwriting the previous cached scene, it adds up. It means that every update, the file size is increasing with the size of the whole scene, more like adding up rather than overwriting.
     
    Last edited: Jan 20, 2020
  8. carlbinalla

    carlbinalla

    Joined:
    Mar 5, 2018
    Posts:
    7
    @unity_bill I'm not sure if you have seen this, but it would be nice to shed some light on this. As I believe that many will want a way to use these methods properly.

    Or if it not possible yet, at least an idea on how to properly overwrite old cached asset with its updated one. So that we can properly say in the UI whether "Download Asset" or "Update Asset"
     
    lclemens likes this.