Is it possible to retrieve a guid from the Catalog at runtime?

By default the guids of the addressable files are included in the catalog. But is there a way to retrieve it?
For example, if I have a texture on the address “myTexture”, is there a way to get the guid of that texture?

AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
List<AddressableAssetEntry> allEntries = new List<AddressableAssetEntry>(settings.groups.SelectMany(g => g.entries));

That allEntries has the address and guid but can only be accessed in editor. Any way to access the guids in the catalog during runtime?

Hi @Laiken it’s a little tricky to do at runtime. You can use Addressables.ResourceLocators to retrieve a mapping of all keys to their resource locations, but keys could refer to a guid, address, or label. So what you can do is reverse the elements of the dictionary. The guid associated with a particular address will reference the same location.

Addressables.InitializeAsync().WaitForCompletion(); // populate ResourceLocators
var locToKeys = new Dictionary<string, List<object>>();
foreach (IResourceLocator locator in Addressables.ResourceLocators)
{
    ResourceLocationMap map = locator as ResourceLocationMap;
    if (map == null)
        continue;
    foreach (KeyValuePair<object, IList<IResourceLocation>> keyToLocs in map.Locations)
    {
        foreach (IResourceLocation loc in keyToLocs.Value)
        {
            if (!locToKeys.ContainsKey(loc.InternalId))
                locToKeys.Add(loc.InternalId, new List<object>(){ keyToLocs.Key });
            else
                locToKeys[loc.InternalId].Add(keyToLocs.Key);
        }
    }
}
1 Like

Thank you pillakirsten!
That worked perfectly.