A people counter
Updated
Reads the roster once with Participants.getSnapshot, then keeps a UI Label up to date with Participants.subscribe, flagging a roster that is still updating.
Read the label and the log. The preview has no room, so the roster is empty; in a published world the count follows people as they come and go.
A people counter
#pragma lifecycle(startup)
function startup() { const count = findEntity('Count').getComponent(UILabelComponent);
const first = Participants.getSnapshot(); log(`${first.count} people when the script started`);
Participants.subscribe((snapshot) => { const approx = snapshot.completeness === 'complete' ? '' : ' (updating)'; count.setProps({ text: `${snapshot.count} here${approx}` }); });}How it works
Section titled “How it works”The script is explained step by step in A people counter.
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.
PeopleCounter.xrproj