Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

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

GUIUtility.GetControlID

Switch to Manual
public static function GetControlID(focus: FocusType): int;
public static function GetControlID(focus: FocusType, position: Rect): int;

Parameters

Description

Get a unique ID for a control.

	// Prints a not used ID that can be assigned to a control

function OnGUI() { // Gets a ID for a control that cannot receive keyboard focus (A button) Debug.Log("Available id: " + GUIUtility.GetControlID(FocusType.Passive)); }

public static function GetControlID(hint: int, focus: FocusType): int;
public static function GetControlID(hint: int, focus: FocusType, position: Rect): int;

Parameters

Description

Get a unique ID for a control, using an integer as a hint to help ensure correct matching of IDs to controls.


public static function GetControlID(contents: GUIContent, focus: FocusType): int;
public static function GetControlID(contents: GUIContent, focus: FocusType, position: Rect): int;

Parameters

Description

Get a unique ID for a control, using a the label content as a hint to help ensure correct matching of IDs to controls.