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 SelectionBasePicker

Attributes: [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

  1. Input filter — only processes left mouse button clicks (MouseDown, button 0)

  2. Object picking — uses HandleUtility.PickGameObject to find the clicked object in the Scene View

  3. Hierarchy walk — calls GetParents() on the picked object and reverses the result (topmost parent first)

  4. SelectionBase search — finds the first (topmost) parent with any component decorated with [SelectionBase]

  5. Selection override — sets Selection.activeGameObject to 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

Goal
How

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).

Parameter
Type
Description

gameObject

GameObject

The object to check

Returns: true if any component has [SelectionBase].

Common Pitfalls

circle-exclamation
circle-exclamation
circle-exclamation
circle-info

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

Last updated