How do you get the "friendly" address of an addressable in C#?

Hello!

I am working on an custom editor window that will store data in a SQLite database. I want to store the address that I specified for a given object in one of the columns. I cannot figure out how to get the address! I have code that does this:

if (_prefabField.value != null && IsAssetAddressable(_prefabField.value))
{
     var tcs = new TaskCompletionSource<bool>();
     var path = AssetDatabase.GetAssetPath(_prefabField.value);
     var assetReference = new AssetReferenceT<GameObject>(path);
}

The problem is that the values stored in assetReference are the full path of the asset - not the addressable address. How can I find this?

Thanks!

Far as I’m aware, AssetReference stores the GUID of the asset (AssetReference.AssetGUID), alongside the sub-object name if referencing one.

It doesn’t contain the asset path at all as they won’t mean anything at runtime.

Got it working. Here’s the code, incase someone else runs into this issue:

if (_prefabField.value != null && IsAssetAddressable(_prefabField.value))
{
    AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
    string assetPath = AssetDatabase.GetAssetPath(_prefabField.value);
    string assetGUID = AssetDatabase.AssetPathToGUID(assetPath);
    AddressableAssetEntry entry = settings.FindAssetEntry(assetGUID);

    Debug.Log(entry.address);
}