Valid Asset Label fails to load: "InvalidKeyException"

I’m trying load a group of addressable assets’ resource locations by label:

if (labelRef.RuntimeKeyIsValid()){
var handle = Addressables.LoadAssetsAsync<IResourceLocation>(labelRef.labelString, DebugLoadedAssets);
yield return handle;}

The label.RuntimeKeyIsValid returns ‘true’, but the operation completes as ‘failed’ with this exception:

“Exception encountered in operation CompletedOperation, status=Failed, result= : Exception of type ‘UnityEngine.AddressableAssets.InvalidKeyException’ was thrown., Key=SCProp, Type=UnityEngine.ResourceManagement.ResourceLocations.IResourceLocation”

I’ve also tried the same logic, but with the handle result type being a standard gameobject instead; I get the same exception. I’ve tried passing the label reference itself, its runtime key, and the label string in the LoadAssetsAsync parameters in case LoadAssetsAsync expects something more specific than the LabelReference object instance. I feel like this is bread and butter Addressables and there’s no clear reason why this isn’t working.

I’m working in Unity 2019.4.10f1 and Addressables version 1.16.16. Any help is appreciated.

Let me flag this one for the team to have a look.

1 Like

Thanks!

In lieu of this, I’ve been using “Addressables.LoadResourceLocationsAsync” and passing an AssetLabelReference as the Key parameter, which gives me resource locations I needed. Am I right in understanding that “Addressables.LoadAssetsAsync” should return the same results (a list of IResourceLocations) if an AssetLabelReference is passed as the key?

Hey @ledbetterMRI

The AssetLabelReference class is only used as a container class to display labels in a PropertyDrawer, in the cases where you would want to display asset reference labels in a custom editor window. RuntimeKeyIsValid() only checks if the string is null or empty, it doesn’t actually look in the catalog.

Don’t use it at runtime, just use strings.

LoadAssetsAsync() returns an actual list of assets, if reachable, whereas LoadResourceLocationsAsync() returns a list of IResourceLocations. It is possible that a call to the former fails if the keys passed as argument aren’t valids or if some locations are not reachable, and that a call to the latter succeeds, because locations are retrieved from the catalog.

I hope I’m answering your questions. Don’t hesitate if there’s anything else.