Use up a scene selection in the editor.

I am working on a custom editor that allows the user to connect one object to another. It ads the selected object to a variable and does some calculation based on the selection.

What i want to do is have the user push a button in the inspector, then a gizmo will be drawn on each of the selectable objects. The user clicks one of the objects to connect to.

The problem is that whenever another object is click the selection changes and the custom inspector is no longer used. So what i want to do is somehow use up the click when a certain type of is clicked, after the “Connect to…” button in the custom inspector has been clicked.

Is there any way to achieve this?

I have tried using Event.current.Use() but it doesn’t seem to do the trick.

Look into HandleUtility.AddDefaultControl which is the control that gets “selected if nothing is selected”. (kindof).

Basically, to prevent deselection, add this to your OnSceneGUI

if (Event.current.type == EventType.Layout)
    HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));