Build a panel from code
Updated
A Behavior script builds a world-space panel from code, with a title, a divider and a hint laid out as a column: UIPanelEntity, UILabelEntity and UIDividerEntity added to the scene.
Drag to orbit the camera around the panel, scroll to zoom.
Build a panel from code
#pragma lifecycle(startup)
function startup() { const panel = new UIPanelEntity(); panel.getComponent(UILayoutComponent).setProps({ width: 360, padding: 20, gap: 12, alignItems: 'center' }); panel.getComponent(UIPanelComponent).setProps({ backgroundColor: '#111827', borderColor: '#334155', borderRadius: 18 });
const title = new UILabelEntity(); title.getComponent(UILabelComponent).setProps({ text: 'Welcome', fontSize: 28 });
const line = new UIDividerEntity();
const hint = new UILabelEntity(); hint.getComponent(UILabelComponent).setProps({ text: 'Walk to the portal to begin.', color: '#a5b4fc' });
panel.add(title, line, hint); panel.position.set(0, 1.6, -2); scene.add(panel);}How it works
Section titled “How it works”The script is explained step by step in Build a panel from code.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
PanelFromCode.xrproj