UI Switch
Updated
An on/off switch.
- Type
comp-ui-switch- Script class
UISwitchComponent- Per entity
- One
- Version
- 1.1.0
Read about it in Controls: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
margin |
||
margin[] |
- |
|
padding |
||
padding[] |
0 ≤ x ≤ 16384 |
Events
Section titled “Events”Sent to the entity’s Signal Emitter as { entityId, eventType, data }. Compare eventType with the EventType constants.
UISwitch::change
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Live example
Move the dialog onto the screenA switch moves a guide's AI Dialog panel and AI Caption between the world, above the guide, and the screen's corner, keeping the world placement for the way back.
Turn on Pin to screen to move the dialog panel to the bottom-right corner of the screen, and off to bring it back above the guide. Moving it needs no AI service; replies need one.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(UISwitchComponent); if (component) log(component.props);}