customProperties

Property

A dictionary of custom properties for the actor. These properties are synchronized across all clients. Only actors themselves can change their own custom properties. An actor's properties are only cleared if they leave the space. Teleporting between servers of the same space will not clear the properties.

Returns IReadOnlyDictionary<string, object>

Examples

int cookieCount = 0;

private void OnEnable()
{
SpatialBridge.actorService.onActorJoined += HandleActorJoined;
}

private void OnDisable()
{
SpatialBridge.actorService.onActorJoined -= HandleActorJoined;
}

private void HandleActorJoined(ActorJoinedEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];

SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " joined the space");

// Subscribe to property changes
actor.onCustomPropertiesChanged += (ActorCustomPropertiesChangedEventArgs customPropertiesArgs) => {
if (customPropertiesArgs.changedProperties.ContainsKey("cookies"))
{
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " has collected " + customPropertiesArgs.changedProperties["cookies"] + " cookies");
}
};
}

private void CollectCookies(int cookies)
{
cookieCount += cookies;
SpatialBridge.actorService.localActor.SetCustomProperty("cookies", cookieCount);
}
int cookieCount = 0;

private void OnEnable()
{
SpatialBridge.actorService.onActorJoined += HandleActorJoined;
}

private void OnDisable()
{
SpatialBridge.actorService.onActorJoined -= HandleActorJoined;
}

private void HandleActorJoined(ActorJoinedEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];

SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " joined the space");

// Subscribe to property changes
actor.onCustomPropertiesChanged += (ActorCustomPropertiesChangedEventArgs customPropertiesArgs) => {
if (customPropertiesArgs.changedProperties.ContainsKey("cookies"))
{
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " has collected " + customPropertiesArgs.changedProperties["cookies"] + " cookies");
}
};
}

private void CollectCookies(int cookies)
{
cookieCount += cookies;
SpatialBridge.actorService.localActor.SetCustomProperty("cookies", cookieCount);
}