Skip to content

UI Checkbox

Updated

A checkbox with a label.

Type
ent-ui-checkbox
Script class
UICheckboxEntity
Family
UI

A UI Checkbox is a small square box with a label beside it that the player ticks on and off. Its UI Checkbox component (comp-ui-checkbox) keeps the state in checked and sends UICheckbox::change with { checked } each time it flips. With radio: true it draws a ring and a dot instead of a box: the classic radio button, for one choice among several. A new checkbox shows the label Checkbox.

Checkboxes sit nested in a panel or layout, usually one per row in a column of options.

Three controls hold an on/off state. Choose by what the player is doing:

  • UI Checkbox: an option the player ticks, such as “I have read the rules”, or one item in a list of choices where several can be on (“Cheese”, “Olives”, “Basil”). With radio: true and a UI Selection Group, one choice among several.
  • UI Switch: a setting that takes effect at once, such as music on or off.
  • UI Toggle Button: a mode or tool shown as a lit button, typically in a toolbar.

The props that matter most:

  • text: the label beside the box. An explicitly empty text draws no label.
  • checked: whether it starts ticked.
  • radio: a round ring and dot instead of a square box.
  • size: the width and height of the box in layout pixels (px).
  • color: one colour for the border, the label and the mark.
  • disabled: dims the checkbox and ignores presses.

From a script, isChecked() reads the state, and setChecked(checked) and toggle() change it. Both send UICheckbox::change, exactly as a press does.

  1. Add a UI Checkbox under a UI Panel or UI Layout, one per option. See Scenes and hierarchy.
  2. Set its text and whether it starts checked.
  3. Add a Signal Emitter with a signal, so it reports each change. Several checkboxes can share one signal.
  4. For radio buttons, set radio: true on each and add a UI Selection Group with the same group name to each.

Goal: keep the Continue button disabled until the player ticks the rules checkbox.

AcceptRules.jx
#pragma lifecycle(startup)
// Scene: a UI Panel holding a UI Checkbox named 'Accept' (Signal Emitter: 'intro:accept')
// and a UI Button named 'Continue' (Signal Emitter: 'intro:continue').
function startup() {
const accept = findEntity('Accept').getComponent(UICheckboxComponent);
const next = findEntity('Continue').getComponent(UIButtonComponent);
accept.setProps({ text: 'I have read the house rules' });
next.setDisabled(!accept.isChecked());
on('intro:accept', (event) => {
if (event.eventType === EventType.UICheckbox.Change) next.setDisabled(!event.data.checked);
});
on('intro:continue', (event) => {
if (event.eventType === EventType.UIButton.Press) emit('intro/done');
});
}

How it works:

  • UICheckbox::change carries the new state in event.data.checked, and the button is disabled whenever it is false.
  • The button starts in the right state because the script reads isChecked() once at start.
  • The Continue listener only runs when the button is enabled, so it never fires before the rules are accepted.

Goal: let the player tick any number of toppings and show the price as they change.

Toppings.jx
#pragma lifecycle(startup)
// Scene: a UI Panel with UI Checkboxes named 'Cheese', 'Olives' and 'Basil',
// each with a Signal Emitter on 'order:topping', and a UI Label named 'Price'.
const PRICES = { Cheese: 1.5, Olives: 1, Basil: 0.5 };
const BASE = 8;
function startup() {
const price = findEntity('Price').getComponent(UILabelComponent);
const boxes = Object.keys(PRICES).map((name) => findEntity(name).getComponent(UICheckboxComponent));
function refresh() {
let total = BASE;
for (const box of boxes) {
if (box.isChecked()) total += PRICES[box.props.text];
}
price.setProps({ text: `Total: ${total.toFixed(2)} coins` });
}
for (const box of boxes) box.setProps({ text: box.entity.name });
on('order:topping', (event) => {
if (event.eventType === EventType.UICheckbox.Change) refresh();
});
refresh();
}

How it works:

  • All three checkboxes share one signal, so one listener reacts to any of them.
  • refresh does not use the event’s data: it reads every checkbox with isChecked() and sums the prices, so the total is always right.
  • box.entity is the entity a component is on, and box.props.text reads the label each box was given.

Goal: three round radio buttons pick one camera view.

CameraView.jx
#pragma lifecycle(startup)
// Scene: UI Checkboxes named 'First person', 'Third person' and 'Top down',
// each with a Signal Emitter on 'settings:view'.
const VIEWS = ['First person', 'Third person', 'Top down'];
function startup() {
for (const name of VIEWS) {
const entity = findEntity(name);
entity.getComponent(UICheckboxComponent).setProps({ text: name, radio: true });
entity.addComponent(new UISelectionGroupComponent({ group: 'camera-view' }));
}
findEntity('Third person').getComponent(UICheckboxComponent).setChecked(true);
on('settings:view', (event) => {
if (event.eventType !== EventType.UICheckbox.Change || !event.data.checked) return;
emit('camera/view', { view: findEntity(event.entityId).name });
});
}

How it works:

  • radio: true draws each checkbox as a ring and dot. The UI Selection Group with the same group makes them exclusive.
  • setChecked(true) picks the starting view and applies the group, so the other two start unticked.
  • The listener acts only on checked: true and reads which view was picked from the entity that sent the event.

What a new UI Checkbox is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.

Component Type Role Per entity What it does
Layer comp-layer Required One Puts the entity on a render/raycast layer so cameras and rays can include or skip it.
Lock comp-lock Required One Editor-only flag that stops the entity from being selected or moved.
Enable comp-enable Required One Turns the entity and its children on or off: hides them and stops their behavior.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
UI Checkbox comp-ui-checkbox Required One A checkbox with a label.

You can also add 5 optional components, such as Networkable, Networkable Trait, Signal Emitter, UI Selection Group, UI Tooltip.

The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).

Prop Default Range
text "Checkbox"
checked false
radio false
disabled false

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • UICheckbox::change

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My UI Checkbox.

UICheckboxEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My UI Checkbox');
if (!(entity instanceof UICheckboxEntity)) return;
// Its UI Checkbox component holds the settings listed under Props.
const component = entity.getComponent(UICheckboxComponent);
log(component.props);
}