Get AssetReference for prefab marked as addressable?

As the title suggests, I’m wondering if there’s a way to get an AssetReference for an addressable prefab through an editor script. I’m adding a component that needs an AssetReference for its own prefab to a whole lot of prefabs, and it sure would be nice not to have to set that up manually for each one!

Use SetEditorAsset

var assetRef = new AssetReference();
assetRef.SetEditorAsset(asset);

If you only have GUID of asset, then

string path = AssetDatabase.GUIDToAssetPath(guid);
var asset = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject;
assetRef.SetEditorAsset(asset);
5 Likes

I tried but both methods bring me back to the scene they reside in