Outline wiring built by a script
Updated
At startup a script gives every Selectable two filtered Signal Emitters, a disabled Outline and two Enable on Signal components, so selecting an object outlines it with no more code.
Click the shapes: the selected one is outlined. Drag to orbit the camera, scroll to zoom.
Outline wiring built by a script
#pragma lifecycle(startup)
function wire(entity) { const id = entity.entityId; entity.addComponent(new SignalEmitterComponent({ signal: id + '/selected', eventFilter: ['Selectable::select'] })); entity.addComponent(new SignalEmitterComponent({ signal: id + '/deselected', eventFilter: ['Selectable::deselect'] }));
const outline = new OutlineComponent({ color: '#38bdf8' }); entity.addComponent(outline); outline.setEnabled(false);
entity.addComponent(new EnableOnSignalComponent({ signal: id + '/selected', action: 'enable', targetFilter: ['Outline'] })); entity.addComponent(new EnableOnSignalComponent({ signal: id + '/deselected', action: 'disable', targetFilter: ['Outline'] }));}
function startup() { let count = 0; scene.entities.forEach((entity) => { if (!entity.getComponent(SelectableComponent)) return; wire(entity); count += 1; }); log('Wired', count, 'selectable entities');}How it works
Section titled “How it works”The script is explained step by step in Outline wiring built by a script.
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.
WireOutline.xrproj