onActorLeft

Event

Event that is triggered when an actor leaves the server (this can be for any reason, including disconnecting, timing out, or being kicked). The actor will still be available on the actors collection while this event is triggered.

Returns IActorService.ActorLeftDelegate

Examples

int cookieCount = 0;

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

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

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 HandleActorLeft(ActorLeftEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " left the space");
}

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

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

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

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 HandleActorLeft(ActorLeftEventArgs args)
{
IActor actor = SpatialBridge.actorService.actors[args.actorNumber];
SpatialBridge.coreGUIService.DisplayToastMessage(actor.displayName + " left the space");
}

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