Skip to content

API Class UIButton

github-actions[bot] edited this page Nov 24, 2026 · 8 revisions

Class: UIButton

Defined in: src/engine/ui/components.ts:214

A panel that takes the pointer. Its children (usually a UIText, which has the font) are its label. Read its state from scripts: hovered, pressed, and clicked, true for the frame a click finished, like Input.getMouseButtonUp. A pointer press on a button goes to the UI, not to Input. The state is the UI core's (its interaction log, ADR 0309).

Extends

  • UIFocusable

Constructors

Constructor

new UIButton(): UIButton;

Defined in: src/engine/ui/components.ts:220

Returns

UIButton

Overrides

UIFocusable.constructor

Properties

alignItems

alignItems: UIAlign = "stretch";

Defined in: src/engine/ui/components.ts:93

Inherited from

UIFocusable.alignItems


backgroundColor

backgroundColor: Color | null = null;

Defined in: src/engine/ui/components.ts:136

Null: transparent.

Inherited from

UIInputField.backgroundColor


borderColor

borderColor: Color = Color.black;

Defined in: src/engine/ui/components.ts:139

Inherited from

UIInputField.borderColor


borderRadius

borderRadius: number = 0;

Defined in: src/engine/ui/components.ts:137

Inherited from

UIInputField.borderRadius


borderWidth

borderWidth: number = 0;

Defined in: src/engine/ui/components.ts:138

Inherited from

UIInputField.borderWidth


bottom

bottom: UILength = "auto";

Defined in: src/engine/ui/components.ts:107

Inherited from

UIFocusable.bottom


display

display: UIDisplay = "flex";

Defined in: src/engine/ui/components.ts:120

none removes the element and its children from layout, drawing and the pointer, like CSS display: none, while its node stays active (its scripts run, and its state reads as before). flex (the default) lays it out.

Inherited from

UIFocusable.display


flexDirection

flexDirection: UIFlexDirection = "row";

Defined in: src/engine/ui/components.ts:91

How this element lays out its children.

Inherited from

UIFocusable.flexDirection


flexGrow

flexGrow: number = 0;

Defined in: src/engine/ui/components.ts:110

How much of the parent's free space this element takes, relative to its siblings.

Inherited from

UIImage.flexGrow


focusable

focusable: boolean = true;

Defined in: src/engine/ui/components.ts:184

False takes it out of focus: navigation skips it and a click doesn't focus it.

Inherited from

UIInputField.focusable


focusColor

focusColor: Color;

Defined in: src/engine/ui/components.ts:186

Drawn while it has focus and the last UI input was navigation, not the pointer.

Inherited from

UIInputField.focusColor


gap

gap: number = 0;

Defined in: src/engine/ui/components.ts:95

Space between children.

Inherited from

UIImage.gap


height

height: UILength = "auto";

Defined in: src/engine/ui/components.ts:102

Inherited from

UIFocusable.height


hoverColor

hoverColor: Color;

Defined in: src/engine/ui/components.ts:215


interactable

interactable: boolean = true;

Defined in: src/engine/ui/components.ts:218

False: the button ignores the pointer (it still blocks it from the game) and stays unhovered.


justifyContent

justifyContent: UIJustify = "flex-start";

Defined in: src/engine/ui/components.ts:92

Inherited from

UIFocusable.justifyContent


left

left: UILength = "auto";

Defined in: src/engine/ui/components.ts:108

Inherited from

UIFocusable.left


margin

margin: number = 0;

Defined in: src/engine/ui/components.ts:99

Space around the element, on every side.

Inherited from

UIImage.margin


navDown

navDown: GameObject | null = null;

Defined in: src/engine/ui/components.ts:191

Inherited from

UIInputField.navDown


navigation

navigation: UINavigationMode = "auto";

Defined in: src/engine/ui/components.ts:188

auto: explicit neighbours, else the nearest element that way; explicit: neighbours only; none: navigate doesn't leave it.

Inherited from

UIFocusable.navigation


navLeft

navLeft: GameObject | null = null;

Defined in: src/engine/ui/components.ts:192

Inherited from

UIInputField.navLeft


navRight

navRight: GameObject | null = null;

Defined in: src/engine/ui/components.ts:193

Inherited from

UIInputField.navRight


navUp

navUp: GameObject | null = null;

Defined in: src/engine/ui/components.ts:190

Explicit neighbours: where navigate up, down, left and right goes from here (null: the search, in auto).

Inherited from

UIInputField.navUp


opacity

opacity: number = 1;

Defined in: src/engine/ui/components.ts:112

0..1, multiplied into its children's.

Inherited from

UIImage.opacity


padding

padding: number = 0;

Defined in: src/engine/ui/components.ts:97

Space inside the element, on every side.

Inherited from

UIImage.padding


positionType

positionType: UIPositionType = "relative";

Defined in: src/engine/ui/components.ts:104

absolute takes the element out of its parent's flow, placed by top/right/bottom/left.

Inherited from

UIFocusable.positionType


pressedColor

pressedColor: Color;

Defined in: src/engine/ui/components.ts:216


raycastTarget

raycastTarget: boolean = true;

Defined in: src/engine/ui/components.ts:129

Whether the pointer stops at this element, like Unity's Graphic.raycastTarget (ADR 0385). True (the default): a press over it goes to the UI, never to the game (Input.pointerOverUI is true), and reaches the button or input field it's in, if any; over text, an image or a panel outside one, it does nothing. False: the pointer passes through to whatever is behind it (other UI, or the game). Text, images, buttons and input fields stop it; a panel only when it draws a background (even a transparent one) or a border, as a panel without either is a layout box (Unity's empty RectTransform). Children aren't affected: each element has its own.

Inherited from

UIImage.raycastTarget


right

right: UILength = "auto";

Defined in: src/engine/ui/components.ts:106

Inherited from

UIFocusable.right


top

top: UILength = "auto";

Defined in: src/engine/ui/components.ts:105

Inherited from

UIFocusable.top


visible

visible: boolean = true;

Defined in: src/engine/ui/components.ts:114

False hides the element and its children but keeps its space (a disabled component or inactive node takes none).

Inherited from

UIImage.visible


width

width: UILength = "auto";

Defined in: src/engine/ui/components.ts:101

Pixels (120), a percentage of the parent ("50%") or "auto" (sized by its content).

Inherited from

UIFocusable.width

Accessors

clicked

Get Signature

get clicked(): boolean;

Defined in: src/engine/ui/components.ts:240

True for the one frame a click on the button finished (pressed and released over it, or submit while it had focus), in every phase of that frame.

Returns

boolean


enabled

Get Signature

get enabled(): boolean;

Defined in: src/engine/core/Component.ts:57

Returns

boolean

Set Signature

set enabled(value): void;

Defined in: src/engine/core/Component.ts:61

Parameters
value

boolean

Returns

void

Inherited from

UIFocusable.enabled


focused

Get Signature

get focused(): boolean;

Defined in: src/engine/ui/components.ts:245

True while it has focus (a click, a script or navigation gave it). Set it to focus or unfocus the button.

Returns

boolean

Set Signature

set focused(value): void;

Defined in: src/engine/ui/components.ts:249

True while it has focus.

Parameters
value

boolean

Returns

void

Overrides

UIFocusable.focused


focusedChanged

Get Signature

get focusedChanged(): boolean;

Defined in: src/engine/ui/components.ts:200

True for the one frame the player (the pointer or navigation) gave it focus or took it away, in every phase of that frame.

Returns

boolean

Inherited from

UIFocusable.focusedChanged


gameObject

Get Signature

get gameObject(): GameObject;

Defined in: src/engine/core/Component.ts:37

Unity-style alias for node.

Returns

GameObject

Inherited from

UIFocusable.gameObject


hovered

Get Signature

get hovered(): boolean;

Defined in: src/engine/ui/components.ts:230

True while the pointer is over the button (and it's interactable).

Returns

boolean


isActiveAndEnabled

Get Signature

get isActiveAndEnabled(): boolean;

Defined in: src/engine/core/Component.ts:68

True when enabled, the node is active in the hierarchy, and the node is in a loaded world.

Returns

boolean

Inherited from

UIFocusable.isActiveAndEnabled


node

Get Signature

get node(): GameObject;

Defined in: src/engine/core/Component.ts:32

The node this component is on.

Returns

GameObject

Inherited from

UIFocusable.node


owner

Get Signature

get owner(): GameObject;

Defined in: src/engine/core/Component.ts:45

The node this component acts for: the node itself when attached directly, or the parent node when this component lives on a component node (ADR 0009).

Returns

GameObject

Inherited from

UIFocusable.owner


pressed

Get Signature

get pressed(): boolean;

Defined in: src/engine/ui/components.ts:235

True from the press on the button until the pointer button is released.

Returns

boolean


time

Get Signature

get time(): Readonly<TimeState>;

Defined in: src/engine/core/Component.ts:93

This component's World's clock (ADR 0032): the same values as Time, but safe to read outside the World's frame too (after an await, say).

Returns

Readonly<TimeState>

Inherited from

UIFocusable.time


transform

Get Signature

get transform(): Transform;

Defined in: src/engine/core/Component.ts:51

The Transform of the node this component is on, if it has one.

Returns

Transform

Inherited from

UIFocusable.transform


world

Get Signature

get world(): WorldHandle;

Defined in: src/engine/core/Component.ts:82

A handle on this component's World (ADR 0132): the same one Engine.findWorld returns. Load a scene into it, pause, connect or destroy it: this.world.loadScene("scenes/level2.scene.json"). Throws for a World no Engine owns.

Returns

WorldHandle

Inherited from

UIFocusable.world

Methods

instantiate()

instantiate(prefabPath, options?): GameObject;

Defined in: src/engine/core/Component.ts:103

Instantiate a prefab in this component's World (ADR 0034), like GameObject.instantiate. Use it in code that may run after an await: by then the frame is over and the current World is the Engine's default one, which may not be this component's. A parent from another World throws.

Parameters

prefabPath

string

options?

InstantiateOptions = {}

Returns

GameObject

Inherited from

UIFocusable.instantiate

Clone this wiki locally