Persistable
Updated
Saves the entity’s state so it is kept between sessions.
- Type
comp-persistable- Script class
PersistableComponent- Per entity
- One
- Version
- 1.1.0
Read about it in Persistence: what it does, how to use it from a script, and examples.
Properties
Section titled “Properties”The props the runtime declares for this component, with their defaults and accepted ranges.
| Prop | Default | Range |
|---|---|---|
retention |
60 ≤ x ≤ 43200 |
Events
Section titled “Events”Sent to the entity’s Signal Emitter as { entityId, eventType, data }. Compare eventType with the EventType constants.
Persistable::changePersistable::clearedPersistable::error
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
Live example
A visit counterA Persistable adds one to a stored count each time the scene starts, with inc, and a UI Label shows the total, or the last known value when the write fails.
Read the label, then run the example again. Without the persistence service the write fails and the label shows the offline value.
From a script
Section titled “From a script”#pragma lifecycle(startup)
function startup() { const component = self.parent.getComponent(PersistableComponent); if (component) log(component.props);}