Relationship and conversion between AssetReference and IResourceLocation

I’ve been experimenting with Addressables and I’m trying to understand how I can use various lookup methods in combination with each other. For instance, it’s awesome to be able to get all assets with a certain label (give me all abilities, all weapons, etc), but I’m stumped when it comes to using that in conjunction with AssetReferences.

Say I use an AssetReference field somewhere in the game to refer to a particular player ability and try to compare the PrimaryKey of it to the one I got earlier from a ResourceLocation loaded via an AssetLabelRerence. To make up an example: I’ll use “FireBasedAbilities” label to get the ResourceLocations of all fire based ability assets, and then I’ll compare AssetReference of a particular ability to the PrimaryKeys of those locations to figure out whether this is a fire based ability.

Even though Addressables can give me the exact same asset using either AssetReference PrimaryKey or ResourceLocation key, there does not appear to be a synchronously comparable equivalence between the two. AssetReference keys appear to be guid strings, whereas ResourceLocation keys are file path strings. I can get a ResourceLocation using the key of the AssetReference, but that’s an async call, and I’d rather avoid doing that mid-game for things that are supposed to be near instantaneous equality checks.

Question 1) Is there a synchronous conversion between AssetReference and ResourceLocation keys that I have missed?

Question 2) More of a suggestion but, would it perhaps be possible to have AssetLocationReference objects that would work exactly like AssetReference except they would use the same key format as ResourceLocation?

3 Likes

Can anyone from Unity help answer my questions or offer alternative workflows?

1 Like

Could @davidla_unity @unity_bill or anyone else chime in?
TL;DR: I want to know if there is a way to compare AssetReference and ResourceLocation synchronously to see if they point to the same local asset.

Hey @taylank1 ! Sorry you’re experiencing workflow issues. I’ll forward this to the team and hopefully get an answer to you soon.

Thank you, Carol. Since posting the question I found that Addressables.Initialize() will give me an IResourceLocator object that maps locations to keys, so I have been using that. If there is a different way of achieving the same goal, I’d be happy to know that too.

1 Like

Will do!

Hey @taylank1 there really isn’t a good way to do what you’re asking. Using that object given from Initialize is probably your best bet.

I also came accross this problem.
Any chance this could be added in the near future?
The key is shown in the inspector for an AssetReference already, so why should there not be an easy way to access it from code?

1 Like