- Home /
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
Answer by deathbypixel · May 15, 2014 at 10:34 PM
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.
It seems that when you select an asset in the projector, the memory increases. So I guess the editor itself also does a loading process when select an object.
Answer by coldstar · Nov 13, 2015 at 03:43 PM
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.