SceneView Selection override using FocusMode.Passive

Hi guys !

I’m currently working on our internal map editor for our project. The goal being to fasten the map production process and to allow our artists to “paint” their map without dealing with all the Unity tools.

I’m using

HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));

to “lock” my SceneView, and I’ll also hide all the Map children in the hierarchy.

The problem I have now is object selection on the map : with FocusType.Passive I have to override every event, which is not a problem, except that I would have to add colliders to all my objects to select them using a raycast.
Obviously I don’t want to do that, it’s a bit overkill and I would have to remove all my colliders when packing the map (not a big deal, but still).
My only goal here is to get the “clicked” Gameobject(s) and I would rather use the default Selection tool, and still keep my map in focus.

Problem is, I can’t find any way to do so. I tried decompiling a bit UnityEditor.dll in Visual Studio to understand how object selection works in the SceneView, without luck.
I also tried to do something like that in my Map CustomInspector:

Selection.selectionChanged = () => {
            if(Selection.activeGameObject != _map) {
            _selectedGameObject = Selection.activeGameObject;
            Selection.objects = new[] {_map}; }
            Debug.Log("Selecting the map again");
};

but sadly this is not working. It may work in a EditorWindow ?

Thanks for your help :slight_smile:

Edit : Well, ofc the callback could not work, as it may create a loop (even if it seems Selection.objects is just not setting anything …). I fixed that, but still nothing

Well, it seems that you can’t assign a new Selection in this callback (which may makes sense, it may also be a bug), so sadly this won’t work.
The simplest solution I found is to put all my code in a EditorWindow, so my UI (SceneGUI) will still be displayed even if the user selects another object. Not perfect, but hey …

Hi, did you had any luck having a mix of default and custom behaviour ?