Version: Unity 6.0 (6000.0)
LanguageEnglish
  • C#

Toggle

class in UnityEngine.UIElements

/

Inherits from:UIElements.BaseBoolField

/

Implemented in:UnityEngine.UIElementsModule

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

Submission failed

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

Close

Cancel

Description

A Toggle is a clickable element that represents a boolean value.

A Toggle control consists of a label and an input field. The input field contains a sprite for the control. By default, this is a checkbox (Unity does not provide a separate checkbox control type) in all of its possible states, for example, normal, hovered, checked, and unchecked. You can style a Toggle control to change its appearance to something else, for example, an on/off switch.

When a Toggle is clicked, its state alternates between between true and false. You can also think of these states as on and off, or enabled and disabled.

To bind the Toggle's state to a boolean variable, set thebinding-path property in a UI Document (.uxml file), or the C# bindingPath to the variable name.

For more information, refer to UXML element Toggle.

Static Properties

Description
checkmarkUssClassName USS class name of Images in Toggle elements.
inputUssClassName USS class name of input elements in Toggle elements.
labelUssClassName USS class name for Labels in Toggle elements.
mixedValuesUssClassName USS class name of Toggle elements that have mixed values
noTextVariantUssClassName USS class name of Toggle elements that have no text.
textUssClassName USS class name of Text elements in Toggle elements.
ussClassName USS class name for Toggle elements.

Constructors

Description
Toggle Creates a Toggle with no label.

Inherited Members

Static Properties

Description
alignedFieldUssClassName USS class name of elements that are aligned in a inspector element
inputUssClassName USS class name of input elements in elements of this type.
labelDraggerVariantUssClassName USS class name of labels in elements of this type, when there is a dragger attached on them.
labelUssClassName USS class name of labels in elements of this type.
mixedValueLabelUssClassName USS class name of elements that show mixed values
noLabelVariantUssClassName USS class name of elements of this type, when there is no label.
ussClassName USS class name of elements of this type.
disabledUssClassName USS class name of local disabled elements.

Properties

Description
text Optional text that appears after the BaseBoolField.
toggleOnLabelClick Whether to activate the toggle when the user clicks the label.
label The string representing the label that will appear beside the field. If the string is empty, the label element is removed from the hierarchy. If the string is not empty, the label element is added to the hierarchy.
labelElement This is the Label object that appears beside the input for the field.
mixedValueLabel Read-only label used to give the appearance of editing multiple different values.
rawValue The value of the element.
showMixedValue When set to true, gives the field the appearance of editing multiple different values.
value The value associated with the field.
binding Binding object that will be updated.
bindingPath Path of the target property to be bound.
canGrabFocus Return true if the element can be focused.
delegatesFocus Whether the element should delegate the focus to its children.
focusable True if the element can be focused.
focusController Return the focus controller for this element.
tabIndex An integer used to sort focusables in the focus ring. Must be greater than or equal to zero.
childCount Number of child elements in this object's contentContainer.
contentContainer Child elements are added to it, usually this is the same as the element itself.
contentRect The rectangle of the content area of the element, in the local space of the element. (Read Only)
customStyle The custom style properties accessor of a VisualElement (Read Only).
dataSource Assigns a data source to this VisualElement which overrides any inherited data source. This data source is inherited by all children.
dataSourcePath Path from the data source to the value.
dataSourceType The possible type of data source assignable to this VisualElement. This information is only used by the UI Builder as a hint to provide some completion to the data source path field when the effective data source cannot be specified at design time.
disablePlayModeTint Play-mode tint is applied by default unless this is set to true. It's applied hierarchically to this VisualElement and to all its children that exist on an editor panel.
enabledInHierarchy Returns true if the VisualElement is enabled in its own hierarchy.
enabledSelf Returns true if the VisualElement is enabled locally.
experimental Returns the UIElements experimental interfaces.