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

2 Answers

2

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! TimK's Resources.Load approach seems to occasionally not work, perhaps if the user hasn't highlighted the object manually at least once first?

–

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.

–

Okay, edited my answer to suit your needs =)

–

It works. thank you

–