Crates that come back
Updated
Grabbable crates with dynamic bodies on a small platform: one script logs each pickup and puts back any crate that falls off the edge.
Drag a crate off the platform and let it fall. Scroll to zoom.
Crates that come back
#pragma lifecycle(startup, update)
const FLOOR_LIMIT = -5; // below this height, the crate has fallen offconst crates = [];
function startup() { for (const name of ['Crate A', 'Crate B', 'Crate C']) { const entity = findEntity(name); crates.push({ entity, grab: entity.getComponent(GrabbableComponent), home: entity.position.clone() }); }
on('crates', (event) => { if (event.eventType === EventType.Grabbable.Start) log(`Picked up with ${event.data.pointerType}`); if (event.eventType === EventType.Grabbable.End) emit('sfx/drop', { id: event.entityId }); });}
function update() { for (const crate of crates) { if (crate.grab.isGrabbed || crate.entity.position.y > FLOOR_LIMIT) continue; crate.entity.setPosition(crate.home.x, crate.home.y, crate.home.z); log(`${crate.entity.name} returned`); }}How it works
Section titled “How it works”The script is explained step by step in Crates that come back.
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.
CrateReturn.xrproj