Keep a companion across scenes
Updated
An amber companion orb has a Don’t Unload component, so when you click a door and the project switches between the meadow and the cave scene, the orb, and the script on it, move with you while everything else is replaced.
Click the blue door to go to the cave, then the green door to come back: the orb stays with you and keeps counting the trips. Drag to orbit the camera, scroll to zoom.
Keep a companion across scenes
#pragma lifecycle(startup, update)
// Don't Unload on the Companion keeps this script running in every scene.let trips = 0;let orb;
function sceneId(name) { return Scenes.list().find((s) => s.name === name)?.id;}
function startup() { orb = self.parent; log("The companion has Don't Unload: it will follow you to the next scene"); on('travel/next', (event) => { if (event.eventType !== EventType.Selectable.Select) return; findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again const next = findEntity('Cave Sign') ? 'meadow' : 'cave'; trips += 1; log(`Trip ${trips}: to the ${next}, and the companion comes along`); Scenes.load(sceneId(next)); });}
function update(dt, time) { orb.position.y = 1.3 + Math.sin(time * 2) * 0.15; orb.rotation.y = time;}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.
CompanionDontUnload.xrproj