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. Dismiss Notice

Question Getting update download size

Discussion in 'Addressables' started by Fiffe, Sep 1, 2020.

  1. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    Hello everyone.

    We are trying to implement addressables updates into our game (using RemoteBuildPath and RemoteLoadPath with CanChangePostRelease) and it seems to be working fine using 1.12.0, the problem though is that we are releasing on Apple's AppStore and our users use cellular in most cases so we are required to show the download size and ask the user whether its fine to download that much.

    The scenario I'm testing works like this:
    I've got 6 groups that are loaded locally and cannot change post release, and 2 groups loaded remotely that can change post release. I build addressables using the default build script, upload files to my CDN and run the editor using "Use Existing Build".

    This is the code that runs in the beginning:

    Code (CSharp):
    1.         public void Initialize()
    2.         {
    3.             Addressables.InitializeAsync().Completed += OnInitialized;
    4.         }
    5.  
    6.         private void OnInitialized(AsyncOperationHandle<IResourceLocator> handle)
    7.         {
    8.             if (handle.Status != AsyncOperationStatus.Succeeded)
    9.             {
    10.                 Debug.LogError("Could not initialize Addressables!");
    11.                 return;
    12.             }
    13.  
    14.             Addressables.CheckForCatalogUpdates().Completed += OnUpdatesChecked;
    15.         }
    16.  
    17.         private void OnUpdatesChecked(AsyncOperationHandle<List<string>> obj)
    18.         {
    19.             Debug.Log("Addressables found " + obj.Result.Count + " updates!");
    20.  
    21.             if (obj.Result.Count > 0)
    22.             {
    23.                 foreach (string key in obj.Result)
    24.                 {
    25.                     Debug.Log("Key: " + key);
    26.                  
    27.                     Addressables.GetDownloadSizeAsync(key).Completed += OnDownloadSizeReceived;
    28.                 }
    29.              
    30.                 _signalBus.Fire(new ShowUpdatePopupSignal(UpdateCatalogs, ContinueInitialization));
    31.              
    32.                 return;
    33.             }
    34.  
    35.             IsInitialized = true;
    36.         }
    37.  
    38.         private void OnDownloadSizeReceived(AsyncOperationHandle<long> obj)
    39.         {
    40.             Debug.Log("Download size is " + obj.Result);
    41.         }
    42.  
    43.         private void UpdateCatalogs()
    44.         {
    45.             Addressables.UpdateCatalogs().Completed += OnCatalogsUpdates;
    46.         }
    47.  
    48.         private void ContinueInitialization()
    49.         {
    50.             Debug.Log($"Successfully initialized {Name}!");
    51.  
    52.             IsInitialized = true;
    53.         }
    54.  
    55.         private void OnCatalogsUpdates(AsyncOperationHandle<List<IResourceLocator>> obj)
    56.         {
    57.             ContinueInitialization();
    58.         }
    You can see that @ line 25 im trying to Debug.Log the key of result of Addressables.CheckForCatalogUpdates() and trying to get it's download size, but the thing is that when my game runs the key is "AddressablesMainContentCatalog" and it will throw an InvalidKeyException as soon as I run Addressables.GetDownloadSizeAsync() with it.

    So the questions appear: how am I supposed to get the keys that got updated in the latest build and how am I supposed to get the keys that got added with the latest build and weren't even there ever?

    Here's how my Addressables Groups look like:



    Any help would be greatly appreciated!
     
  2. Fiffe

    Fiffe

    Joined:
    Dec 10, 2014
    Posts:
    19
    @update @BUMP

    I managed to get the correct file size but it seems like in order to get the handles that should get updated you need to download them first which is not really what I want.
    Right now I am checking if there are any Catalogs to update and if their count is higher than 0 I am running

    Addressables.UpdateCatalogs(catalogs.Result).Completed += OnCatalogsUpdate;


    Which results in this code:
    Code (CSharp):
    1.         private void OnCatalogsUpdate(AsyncOperationHandle<List<IResourceLocator>> locators)
    2.         {
    3.             _locators = locators.Result;
    4.  
    5.             List<object> keys = new List<object>();
    6.          
    7.             foreach (IResourceLocator locator in locators.Result)
    8.             {
    9.                 keys.AddRange(locator.Keys);
    10.             }
    11.          
    12.             Addressables.GetDownloadSizeAsync(keys).Completed += OnDownloadSizeReceived;
    13.         }
    14.  
    15.         private void OnDownloadSizeReceived(AsyncOperationHandle<long> obj)
    16.         {
    17.             Debug.Log("Download size is " + obj.Result);
    18.  
    19.             foreach (IResourceLocator locator in _locators)
    20.             {
    21.                 foreach (object key in locator.Keys)
    22.                 {
    23.                     ClearDependencyCacheForKey(key);
    24.                 }
    25.             }
    26.          
    27.             _signalBus.Fire(new ShowUpdatePopupSignal(obj.Result, UpdateDependencies, ContinueInitialization));
    28.         }
    29.  
    30.       private void UpdateDependencies()
    31.       {
    32.           Addressables.DownloadDependenciesAsync(_locators, true).Completed +=       ContinueInitialization;
    33.       }
    34.  
    This gives me correct file size but if I decide to quit the game before pressing the Update button (which should Invoke UpdateDependencies) and then start it again the content is already downloaded. Does anyone know how to prevent the download before I press the Update button?
     
    xifeng8445 likes this.
  3. xifeng8445

    xifeng8445

    Joined:
    Mar 12, 2019
    Posts:
    2
    I'm having the same problem as you, I don't click download to exit the program and then restart it, but the resources get downloaded. Looking forward to a good solution to your problem.
     
  4. Trisibo

    Trisibo

    Joined:
    Nov 1, 2010
    Posts:
    233
    @Fiffe @xifeng8445
    Are you sure the bundles are downloaded? I also thought that was the case when doing some tests, but then I realized they are definitely not downloaded when updating the catalog, what is happening is that the app won't use the old bundles anymore, so it downloads the new ones only when you try to load them. So the actual question would be how to download an updated catalog without the app using it as the current one, to be able to keep using the old bundles if desired.