How do I use EditorGUIUtility.ShowObjectPicker()? C#

No code example, documentation is vague, and google yields nothing.
Anyone know what they’re doing with this?

Also why couldn’t it be:
Object ShowObjectPicker( ObjectClass class, bool showSceneObjects )

As it is a unity editor function, I assume that’s the most streamlined method.
(Most everything else in editor is thread pausing, why not the object picker?)

1 Like

I was still not sure how you use the control ID for a picker window. Here is what I did to get multiple object fields working with the picker.

Use the following code to open up a picker window with a specific control ID.

//in your EditorWindow class

int currentPickerWindow;

void ShowPicker() {
	//create a window picker control ID
	currentPickerWindow = EditorGUIUtility.GetControlID(FocusType.Passive) + 100;

	//use the ID you just created
	EditorGUIUtility.ShowObjectPicker<GameObject>(null,false,"ee",currentPickerWindow);
}

Then, in your method that draws the object field check for the event commandname “ObjectSelectorUpdated” and check if the open picker has your custom controlID. EditorGUIUtility.GetObjectPickerObject() should be the picker object you want.

Object effectGO = null;

if( Event.current.commandName == "ObjectSelectorUpdated" && EditorGUIUtility.GetObjectPickerControlID() == currentPickerWindow )
{		
	
	effectGO = EditorGUIUtility.GetObjectPickerObject();
	currentPickerWindow = -1;

	//name of selected object from picker
	Debug.Log(effectGO.name);
}

To act on the “events” provided by the object picker, try this somewhere in the body of your OnGUI method:

if (Event.current.commandName == "ObjectSelectorUpdated")
{
     // do a thing relating to the object picker
}

Take a look at the Event class for some more info about consuming the events posted by the Object picker.

This really pissed me off. That goddamn showobjectpicker.

Anyways, I found a script from some Japanese place that works. He basically made it looked at normal objects. I only changed it to Texture2D.

So if you check here and just change the Object texts to Texture2D. It’ll work.

http://anchan828.hatenablog.jp/entry/2013/11/15/143139

Can’t believe my eyes. After desperately searching all over the internet I finally found this piece of art: GitHub - MPozek/Pickle: A better object picker for Unity engine :star_struck: