ShowObjectPicker ObjectSelectorClosed command is never issued

Hi, I have troubles catching Event.current.commandName == “ObjectSelectorUpdated” after invoking ObjectPicker and selecting something in it.

First I invoke the ObjectPicker after recieving an event. myObject is just a null Brain.

void OnPullingFromBrain(object obj, System.EventArgs e)
        {
            EditorGUIUtility.ShowObjectPicker<Brain>(myObject, true, "", 1);
        }

Then in OnGUI I’m checking

if (Event.current.commandName == "ObjectSelectorClosed")
            {
                Debug.Log(EditorGUIUtility.GetObjectPickerObject());
            }

However command is always empty string. Even debuging it every OnGUI call I get just bunch of empty strings regardless of ObjectPicker updating, closing or whatever.

Any idea what could cause this?

Solved this myself. The ObjectPicker apparently has to be opened from OnGUI method itself, otherwise it won’t broadcast events to it. I did it like this:

int pickerFlag = 0;
    
    void OnPullingFromBrain(object obj, System.EventArgs e)
    {
          pickerFlag = 1; 
    }
    
    private void OnGUI()
    {
          if (pickerFlag > 0)
                {
                    EditorGUIUtility.ShowObjectPicker<Brain>(myObject, true, "", pickerFlag);
                }
                if (canvasCache.nodeCanvas.canvasName == "Brain" && Event.current.commandName == "ObjectSelectorUpdated")
                {
                    if (EditorGUIUtility.GetObjectPickerControlID() == 1)
                    {
                        Object brainGO = EditorGUIUtility.GetObjectPickerObject();
                        (canvasCache.nodeCanvas as BrainCanvasType).PullFromBrain(brainGO);
                        pickerFlag = 0;
                    }
            }
    }

Sorry for the messy formating.