Skip to main content
Supported on
Snapchat

Sync Realtime Store

SyncRealtimeStore is a Sync Entity and realtime store exposed as a scene component, with no behavior of its own. Use it when you want somewhere to keep synced values without writing a script that constructs a Sync Entity, or when another script needs a store it can reference in the Inspector.

Component Inputs

NameTypeDescription
Network Id TypeObject Id or CustomHow the network id is generated. Defaults to Object Id.
Custom Network IdstringShown when Network Id Type is Custom. Defaults to enter_unique_id.
OwnershipOwned, Unowned, or Host OwnedWho may write to the store. Defaults to Unowned.

Component API

Name (signature)Description
syncEntityThe underlying Sync Entity.
isStoreReady(): booleanWhether the store exists and is ready.
getStore(): GeneralDataStore | nullThe underlying store.
getStoreOwnerInfo(): ConnectedLensModule.UserInfo | nullCurrent owner, if any.
canIModifyStore(): booleanWhether the local client may write. Check before writing.
doIOwnStore(): booleanWhether the local client owns the store.
isStoreOwned(): booleanWhether anyone owns the store.
isHostOwned(): booleanWhether the store is host-owned.
addStorageProperty<T>(storageProperty: StorageProperty<T>): StorageProperty<T>Adds a storage property to the store, returning it.

Events

These pass straight through from the underlying Sync Entity: onStoreCreated, onStoreUpdated, onStoreOwnershipUpdated, onStoreDeleted, onSetupFinished, onOwnerUpdated.

Usage

import { SyncRealtimeStore } from 'ConnectedFramework.lspkg/Components/SyncRealtimeStore';
import { StorageProperty } from 'ConnectedFramework.lspkg/Core/StorageProperty';

@component
export class RoundTimer extends BaseScriptComponent {
@input
store!: SyncRealtimeStore;

private secondsLeft!: StorageProperty<number>;

onAwake() {
this.secondsLeft = this.store.addStorageProperty(
StorageProperty.manualInt('secondsLeft', 60)
);

this.store.onSetupFinished.add(() => {
print(`Timer ready at ${this.secondsLeft.currentValue}`);
});
}
}
Was this page helpful?
Yes
No