Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback LoadContentCatalogAsync + GetDownloadSizeAsync API usability issue

Discussion in 'Addressables' started by Prodigga, Jul 16, 2020.

  1. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Hello there

    I just ran into a gotcha when loading catalogue manually, and using GetDownloadSizeAsync with the result.

    Consider the following code:
    Code (CSharp):
    1. Addressables.LoadContentCatalogAsync(catalogueURL).Completed += r =>
    2.             {
    3.                 Addressables.GetDownloadSizeAsync(r.Result.Keys).Completed += rr =>
    4.                 {
    5.                     ....
    GetDownloadSizeAsync has 2 overrides. One takes an object as a key, and the other takes a IList<object> as a list of keys to check. If you pass in the Keys of the catalogue you just loaded, it will use the object overload of GetDownloadSizeAsync, treating your collection of keys as a single key. This ofcourse throws an exception:
    Code (CSharp):
    1. Exception encountered in operation UnityEngine.ResourceManagement.ResourceManager+CompletedOperation`1[System.Int64], result='', status='Failed': Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown.,
    This is because Keys is an IEnumerable<object>, not an IList<object>. I feel like most developers are going to be caught out by this!

    Maybe we can have GetDownloadSizeForKeyAsync and GetDownloadSizeForKeysAsync, or GetDownloadSizeAsync can be modified to accept an IEnumerable<object> instead of an IList<object> of keys.

    The workaround is this, which feels a little icky:
    Code (CSharp):
    1. Addressables.LoadContentCatalogAsync(catalogueURL).Completed += r =>
    2.             {
    3.                 Addressables.GetDownloadSizeAsync(r.Result.Keys.ToList()).Completed += rr =>
    4.                 {
    5.                     ....
     
    TomPorter1 and dlegare-synapse like this.
  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    583
    Yup it's not great. I use
    new List<object>(r.Result.Keys)
    to avoid linq, but either way it's wasteful.