Version: Unity 6.0 (6000.0)
LanguageEnglish
  • C#

Button

class in UnityEngine.UIElements

/

Inherits from:UIElements.TextElement

/

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

This is a clickable button.

A Button has a text label element that can respond to pointer and mouse events. You can add an icon to pair it with the text by assigning a Background (Texture, RenderTexture, Sprite or Vector Image) to the iconImage API or icon-image UXML property. Please note that by providing an icon image, this will automatically update the Button's hierarchy to contain an Image and a text label element.

By default, a single left mouse click activates the Button's Clickable property button. To remove this activator, or add more activators, modify the clickable.activators property. For details, see ManipulatorActivationFilter.

To bind a Button's text value to the contents of a variable, set the binding-path property in the UXML file, or the bindingPath property in the C# code, to a string that contains the variable name.

For more information, refer to UXML element Button.

Static Properties

Property Description
iconOnlyUssClassName The USS class name for Button elements with an icon only, no text.
iconUssClassName The USS class name for Button elements with an icon.
imageUSSClassName The USS class name of the image element that will be used to display the icon texture.
ussClassName USS class name of elements of this type.

Properties

Property Description
clickable Clickable MouseManipulator for this Button.
iconImage The Texture, Sprite, or VectorImage that will represent an icon within a Button element.

Constructors

Constructor Description
Button Constructs a Button.

Events

Event Description
clicked Callback triggered when the button is clicked.
onClick Obsolete. Use clicked instead.

Inherited Members

Static Properties

PropertyDescription
selectableUssClassName USS class name of selectable text elements.
ussClassName USS class name of elements of this type.
disabledUssClassName USS class name of local disabled elements.

Properties

PropertyDescription
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.