Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


Selection

Provides access to the selection in the Editor.
Read time 2 minutesLast updated 3 days ago

Definition

  • Type: Class
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule
public sealed class Selection

Remarks

The selection API tracks Object-based selections. Object-based selections are where the inspector window displays the selected object or objects.
If you have an Editor window or an Editor tool that has custom selections, and you want them to be recorded in the Editor's selection history use Selection.RegisterCustomHandler and Selection.SetCustomSelection. In the Editor, you can use the Previous Selection and Next Selection buttons in the main toolbar to cycle through your selection history.

Static Fields

Value

Description

selectionChangedDelegate callback triggered when currently active/selected item has changed.

Static Properties

Property

Description

activeContextReturns the current context object, as was set via SetActiveObjectWithContext.
activeEntityIdReturns the entityId of the actual object selection. Includes Prefabs, non-modifiable objects.
activeGameObjectReturns the active game object. (The one shown in the inspector).
activeObjectReturns the actual object selection. Includes Prefabs, non-modifiable objects.
activeTransformReturns the active transform. (The one shown in the inspector).
assetGUIDsReturns the guids of the selected assets.
countReturns the number of objects in the Selection.
entityIdsThe actual unfiltered selection from the Scene returned as entityIds instead of Selection.objects.
gameObjectsReturns the actual game object selection. Includes Prefabs, non-modifiable objects.
objectsThe actual unfiltered selection from the Scene.
transformsReturns the top level selection, excluding Prefabs.

Static Methods

Method

Description

ContainsReturns whether an object is contained in the current selection.
GetFilteredReturns the current selection filtered by type and mode.
GetTransformsRetrieves the transforms of selected objects.
RegisterCustomHandlerRegisters a handler for custom non-Object based selection in selection history.
SetActiveObjectWithContextSelects an object with a context.
SetCustomSelectionRecords a custom selection in the Editor's selection history.
UnregisterCustomHandlerUnregisters the current handler and validator for the given
key