Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Selection.GetFiltered

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function GetFiltered(type: Type, mode: SelectionMode): Object[];
public static Object[] GetFiltered(Type type, SelectionMode mode);
public static def GetFiltered(type as Type, mode as SelectionMode) as Object[]

Parameters

type Only objects of this type will be retrieved.
mode Further options to refine the selection.

Description

Returns the current selection filtered by type and mode.

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.

class ToggleActive extends ScriptableObject {
    @MenuItem ("Example/Toggle Active of Selected %i")
    static function DoToggle() {
        var activeGOs: Object[] =
            Selection.GetFiltered(
                GameObject,
                SelectionMode.Editable | SelectionMode.TopLevel);

for (var obj in activeGOs) var activeGO = obj as GameObject; activeGO.SetActive(!activeGO.activeSelf); } }