SelectionBasePicker
Internal utility that enhances Scene View object picking by automatically selecting the topmost parent GameObject with a [SelectionBase] component when clicking on any child object in the hierarchy.
Definition
Namespace: Paragon.Editor Assembly: Paragon.Editor.dll
[InitializeOnLoad]
internal static class SelectionBasePickerAttributes: [InitializeOnLoad] — initializes via static constructor on editor load.
Remarks
Unity's built-in [SelectionBase] attribute marks a component's GameObject as a selection root. However, Unity's default behavior only applies [SelectionBase] for the immediate parent — not for deeply nested hierarchies. This utility extends that behavior by walking the entire parent hierarchy to find the topmost [SelectionBase] component.
Selection Algorithm
Input filter — only processes left mouse button clicks (
MouseDown, button 0)Object picking — uses
HandleUtility.PickGameObjectto find the clicked object in the Scene ViewHierarchy walk — calls
GetParents()on the picked object and reverses the result (topmost parent first)SelectionBase search — finds the first (topmost) parent with any component decorated with
[SelectionBase]Selection override — sets
Selection.activeGameObjectto the selection base and consumes the event
Parent Traversal Order
GetParents().Reverse() produces a top-down order (root → parent → child). FirstOrDefault returns the topmost parent with [SelectionBase], not the nearest. This means clicking any descendant will always select the root selection base.
Quick Lookup
Mark a component as selection base
Add [SelectionBase] attribute to the component class
Behavior
Left-click on any child → topmost [SelectionBase] parent is selected
Event handling
The click event is consumed (Event.current.Use())
Methods
OnSceneGUI (private static)
Callback for SceneView.duringSceneGui. Processes left-click events by picking the clicked object and selecting its topmost [SelectionBase] ancestor.
HasAnySelectionBaseComponent (private static)
Checks if any component on the GameObject has the [SelectionBase] attribute (including inherited).
gameObject
GameObject
The object to check
Returns: true if any component has [SelectionBase].
Common Pitfalls
Topmost selection base wins The utility selects the topmost (closest to root) parent with [SelectionBase]. If the hierarchy has multiple [SelectionBase] components at different levels, only the topmost one is selected. To reach a nested selection base, double-click or use the Hierarchy window.
Event consumption The click event is consumed via Event.current.Use() when a selection base is found. This prevents Unity's default object selection from also processing the click, which could result in selecting the wrong object.
Internal class — always active SelectionBasePicker is internal static and cannot be disabled. It runs on every left-click in the Scene View and overrides selection when a [SelectionBase] parent exists.
No selection base found If no parent has [SelectionBase], the utility does nothing and Unity's default selection behavior applies normally.
Examples
Using SelectionBase with a Character
Nested Hierarchy
See Also
Utility Overview — utility subsystem
Paragon Editor Overview — root editor module
Last updated