Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetFiltered

Returns the current selection filtered by type and mode.
Read time 1 minuteLast updated 5 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor

GetFiltered<T>(SelectionMode)

Returns the current selection filtered by type and mode.
public static T[] GetFiltered<T>(SelectionMode mode)

Parameters

Further options to refine the selection.

Returns

Type

Description

<T>[]

Remarks

For a selected GameObject that has multiple Components of type, only the first one will be included in the results.
If type is a subclass of Component or GameObject the full SelectionMode is supported.
If type does not subclass from Component or GameObject (eg. Mesh or ScriptableObject) only SelectionMode.ExcludePrefab and SelectionMode.Editable are supported.

Examples

using UnityEngine;using UnityEditor;class ToggleActive : ScriptableObject{ [MenuItem("Example/Toggle Active of Selected %i")] static void DoToggle() { Object[] activeGOs = Selection.GetFiltered( typeof(GameObject), SelectionMode.Editable | SelectionMode.TopLevel); foreach (GameObject obj in activeGOs) { obj.SetActive(!obj.activeSelf); } }}

GetFiltered(Type, SelectionMode)

Returns the current selection filtered by type and mode.
public static Object[] GetFiltered(Type type, SelectionMode mode)

Parameters

type

Only objects of this type will be retrieved.

Further options to refine the selection.

Returns

Type

Description

Object[]

Remarks

For a selected GameObject that has multiple Components of type, only the first one will be included in the results.
If type is a subclass of Component or GameObject the full SelectionMode is supported.
If type does not subclass from Component or GameObject (eg. Mesh or ScriptableObject) only SelectionMode.ExcludePrefab and SelectionMode.Editable are supported.

Examples

using UnityEngine;using UnityEditor;class ToggleActive : ScriptableObject{ [MenuItem("Example/Toggle Active of Selected %i")] static void DoToggle() { Object[] activeGOs = Selection.GetFiltered( typeof(GameObject), SelectionMode.Editable | SelectionMode.TopLevel); foreach (GameObject obj in activeGOs) { obj.SetActive(!obj.activeSelf); } }}