A crate everyone can move
Updated
Your first shared object: a grabbable crate with a Networkable and transform and material traits; whoever takes it gives it a new colour for everyone.
Drag the crate. The preview has no Arena room, so the log says you are playing alone; in a published world, open it in two tabs to see the crate move and change colour in both.
A crate everyone can move
#pragma lifecycle(startup)
const COLORS = ['#f97316', '#22c55e', '#3b82f6', '#e11d48', '#eab308'];
let crate;let net;let material;
function startup() { crate = findEntity('Crate'); net = crate.getComponent(NetworkableComponent); material = crate.getComponent(StandardMaterialComponent);
log(Network.connected ? `In room ${Network.room} as ${Network.peerId}` : 'Playing alone');
on('crate/net', (event) => { if (event.eventType === EventType.Networkable.OwnershipChange && event.data.isOwner) { // Only the new owner writes, and its change travels to everyone. const color = COLORS[Math.floor(Math.random() * COLORS.length)]; material.setProps({ color }); log('I took the crate'); } if (event.eventType === EventType.Networkable.PeerJoin) { log(`Someone joined: ${event.data.peerId}`); } });}How it works
Section titled “How it works”The script is explained step by step in A crate everyone can move.
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.
FirstSharedCrate.xrproj