Scripting API
PersistenceModule
PersistenceModule Overview

PersistenceModule

The Persistence class encapsulates persistent objects, allowing you to store, retrieve and remove data which will persist across multiple sessions.

Persisted data behaves differently in different testing environments. For consistent results, test persistence in your projects using the Restart function in Meta Spark Player (desktop and mobile) and Meta Spark Studio.

userScope and StorageScope have been removed in v157. To update old projects, use Persistence.local instead.

Example

Blocks example

Your script will need to be slightly different if you are using persistence within Blocks. You can download a sample project here.

Both the main script and the script inside the Block are shown below. The main script is responsible for determining where the Block data is stored:

And the script from the Block:

Properties

PropertyDescription
block
(get) block: StorageLocation
(set) (Not Available)


Gets the StorageLocation that stores data for this block. This location only returns data that was stored for the
currently logged-in user. This storage is specific to this instance of the block:
blocks cannot access the data stored by other blocks.
Note: The storage is controlled by the parent during blocks initialization. See also BlockStorage. If no BlockStorage
was configured in Blocks.instantiate() via BlockModulesConfig, then the default will be an in-memory, block instance-scoped
storage.
local
(get) local: StorageLocation
(set) (Not Available)


Gets an instance of StorageLocation that stores data on the user's local
device storage. This location only returns data that was stored for the
currently logged-in user. This storage is specific to the given effect:
effects cannot access the data stored by other effects.
userScope
(get) userScope: StorageScope
(set) (Not Available)


Deprecated. Please use Persistence.local and its StorageLocation class instead.
Gets an instance of StorageScope corresponding to the user scope.

Methods

MethodDescription
blockStorage
blockStorage(storageIdentifier: string): BlockStorage


Represents a BlockStorage for nested Blocks that is scoped the same way as the parent Block's BlockStorage.
The storage location (e.g. local or temporary) is kept the same as its parent Block.
localBlockStorage
localBlockStorage(storageIdentifier: string): BlockStorage


Gets the local BlockStorage instance associated with the storageIdentifier. This storage
is on the user's device.
- calling the API with the same storageIdentifier will return the same BlockStorage object, even if it's completely different Block instances.
- Equivalent to Persistence.local for Blocks.
temporaryBlockStorage
temporaryBlockStorage(storageIdentifier: string): BlockStorage


Gets the temporary BlockStorage instance associated with the storageIdentifier. This storage
goes away once the effect restarts or is unloaded, but it does allow for a
Block to be unloaded and re-loaded during the lifetime of an effect while
maintaining its persistent data.
- calling the API with the same storageIdentifier will return the same BlockStorage object, even if it's completely different Block instances.

Classes

ClassDescription
BlockStorageThis class represents a storage location for a Block's persistent data. Note it gives no access to the actual data stored within.
StorageLocationThe StorageLocation class encapsulates different methods of storage for persistent objects. Now with better error handling.
StorageScopeThe StorageScope class encapsulates different methods of storage for persistent objects.