Set editor selection from GUID/Asset path

Hello!

I would like to select an asset through an editor script. I have the GUID of the actual asset and from that I can get the asset path and vice versa. The problem is that the Selection singleton (with which I assume I can set the selected file) only works on instance IDs which are unique per runtime - and I don’t know how to get the instance id from a GUID or asset path.

The actual effect I’m after is to open the inspector panel and I figured the easiest way would be to just set the current selection but perhaps there is a better approach?

Cheers

I solved this by doing:

Object obj = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));

Selection.activeObject = obj;

I’m not sure why I would have to load the asset, this seems like unneccessary overhead so if anyone has a better idea, please share.

GUID like an unique ID to identify an asset.
Selection need an instance of that asset to select.
So you need to load it first to generate an instance, then the instance can be selected.