Outline the selected object, and restyle it while it is held
Updated
A crate is outlined in a calm style while it is selected, and in a bright sweeping style while it is grabbed, from one listener on all its events.
Click the crate to outline it, drag it to see the held style, and click empty space to clear it. Drag elsewhere to orbit the camera.
Outline the selected object, and restyle it while it is held
#pragma lifecycle(startup)
const IDLE = { color: '#38bdf8', thickness: 4, animation: 'none' };const HELD = { color: '#facc15', thickness: 6, animation: 'sweep', speed: 0.6 };
function startup() { const outline = self.parent.getComponent(OutlineComponent); outline.setProps(IDLE); outline.setEnabled(false);
on('crate/state', (event) => { switch (event.eventType) { case EventType.Selectable.Select: outline.setEnabled(true); break; case EventType.Selectable.Deselect: outline.setEnabled(false); break; case EventType.Grabbable.Start: outline.setProps(HELD); break; case EventType.Grabbable.End: outline.setProps(IDLE); break; } });}How it works
Section titled “How it works”The script is explained step by step in Outline the selected object, and restyle it while it is held.
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.
SelectionOutline.xrproj