Question about Addressables.DownloadDependenciesAsync exception handling

When using DownloadDependenciesAsync to get dependency resources with key(string), if there is no resources with provided key, exception is shown as follows.

Exception encountered in operation CompletedOperation, status=Failed, result= : Exception of type 'UnityEngine.AddressableAssets.InvalidKeyException' was thrown., Key=MG_Destruction, Type=System.Object
UnityEngine.AddressableAssets.Addressables:smile:ownloadDependenciesAsync(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?

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 which you can then check the count of. If its 0, skip that download :slight_smile:

It works like magic!

Thanks for the fast reply.

1 Like