- Home /
How to highlight or select an asset in project window from editor script?
Hi
Is there a function for highlighting assets in project window like when I click on a variable of a script in the Inspector? I'm making an Editor script.
Thanks
Answer by Skjalg · Dec 07, 2010 at 11:15 PM
You could use Selection if you want to mark it in the Project
Selection.gameObjects = new GameObject[] { theGameObjectIwantToSelect };
Or if you want the object to highlight as yellow then you could use PingObject
EditorGUIUtility.PingObject( theObjectIwantToSelect );
Actually I want to "highlight" it like in this picture: http://img34.imageshack.us/img34/914/77510398.jpg
I know that if you insert the gameobject that you want to highlight in as the second paramter of Debug.Log("Hi", theGameObjectIwantToSelect); Then it highlights.
I dont of any other ways.
It only highlights the object when I click on the message in the console.
Answer by grimmy · Oct 22, 2012 at 01:25 PM
Although the above answer seemed to work for many, I couldn't select assets in my project window by following the answer above (only my hierarchy view). However, I managed to select assets by using the following command. Here is an example of selecting a prefab that resides in your Project window.
Selection.activeObject=AssetDatabase.LoadMainAssetAtPath("Assets/Prefabs/"+prefabName+".prefab");
Hope that helps someone!
Yeah I'm not quite sure why that got so many upvotes -- I don't think it actually works for objects in the Project tab, or perhaps you could argue that it omits the most important part: how to actually get an object in the Projects tab as a GameObject you can pass to Selection.
I was able to get this to work much the way you did, although I used Resources:
GameObject prefab = Resources.Load(prefabName);
Selection.activeObject = prefab;
Grimmy's AssetDatabase solution worked for me! Tim$$anonymous$$'s Resources.Load approach seems to occasionally not work, perhaps if the user hasn't highlighted the object manually at least once first?
Your answer
![](https://koobas.hobune.stream/wayback/20220613090142im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting all assets of the specified type 5 Answers
Multiple object Selection in project view: Unity shows wrong type 0 Answers
Getting assets / sub folders inside a folder 1 Answer
How to increase the size of my sprites in the Editor > Project previsualization? 0 Answers
Untangling two projects 1 Answer