Search Unity

Question about Addressables.DownloadDependenciesAsync exception handling

Discussion in 'Addressables' started by ChromeCat, Oct 20, 2020.

  1. ChromeCat

    ChromeCat

    Joined:
    Jan 27, 2016
    Posts:
    35
    When using DownloadDependenciesAsync to get dependency resources with key(string), if there is no resources with provided key, exception is shown as follows.

    Code (CSharp):
    1. Exception encountered in operation CompletedOperation, status=Failed, result= : Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=MG_Destruction, Type=System.Object
    2. UnityEngine.AddressableAssets.Addressables:DownloadDependenciesAsync(Object, Boolean)
    There is a possible case that dependency resource might not exists, so if that exception is thrown, then I just want to ignore that exception and not to show on logger.

    But I can't find a way to not show that exception. try catch doesn't work because DownloadDependenciesAsync is asynchronous method.

    Or if there is CheckDependencyAsync i could check before downloading it.

    Is there any way I could not show that exception if there is no dependency?
     
  2. Lucas-Hehir

    Lucas-Hehir

    Joined:
    Jul 2, 2014
    Posts:
    41
    I think you want to try using Addressables.LoadResourceLocationsAsync before each Download operation.

    First, pass your key/s into LoadResourceLocationsAsync and await the result. Even if the key is invalid, it'll always return a List<IResourceLocation> which you can then check the count of. If its 0, skip that download :)
     
  3. ChromeCat

    ChromeCat

    Joined:
    Jan 27, 2016
    Posts:
    35
    It works like magic!

    Thanks for the fast reply.
     
    Lucas-Hehir likes this.