Dont Unload
Updated
Keeps this entity, and everything under it, when its scene is switched away in play. It moves to the new scene as a child of its root.
- Type
comp-dont-unload- Script class
DontUnloadComponent- Per entity
- One
- Version
- 1.0.0
Read about it in Switching scenes: what it does, how to use it from a script, and examples.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Live example
Keep a companion across scenesAn 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.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(DontUnloadComponent); if (component) log(component.props);}