Switch the world behind the portal
Updated
Three worlds are groups under a circular Mask Mesh with one enabled at a time; Next world closes the portal with a tween, swaps the world and opens it again.
Press Next world to step through the desert, the glacier and space. Drag to orbit the camera, scroll to zoom.
Switch the world behind the portal
#pragma lifecycle(startup)
const WORLDS = ['Desert', 'Glacier', 'Space'];let current = 0;let busy = false;
function setRadius(mask, to, duration) { const from = mask.props.radius; return Tween.value(from, to, (r) => mask.setProps({ radius: r }), { duration: duration, ease: Ease.InOutCubic });}
async function showNext(mask, worlds) { if (busy) return; busy = true;
const open = mask.props.radius; await setRadius(mask, 0.01, 0.3);
worlds[current].setEnabled(false); current = (current + 1) % worlds.length; worlds[current].setEnabled(true);
await setRadius(mask, open, 0.4); busy = false;}
function startup() { const portal = findEntity('Portal'); const mask = portal.getComponent(MaskMeshComponent); mask.setProps({ shape: 'circle' });
const worlds = WORLDS.map((name) => findEntity(name)); worlds.forEach((world, i) => world.setEnabled(i === current));
on('portal/next', () => showNext(mask, worlds));}How it works
Section titled “How it works”The script is explained step by step in Switch the world behind the portal.
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.
PortalWorlds.xrproj