Data Subscriptions & Live Updates
This document describes the current data subscription API in PlayServ Unity SDK.
Create subscription
Use PlayServ.SelectEntity<TEntity, TDto>(id, map):
var player = await PlayServ.SelectEntity<SamplePlayerEntity, SamplePlayerDto>(
"player-001",
entity => new SamplePlayerDto
{
Id = entity?.Id ?? string.Empty,
Name = entity?.Name ?? string.Empty,
Level = entity?.Level ?? 0
});This returns ISharedEntity<SamplePlayerDto> with live value sync.
Observe updates
player.Changed += dto =>
{
Debug.Log($"Player updated: {dto.Id} {dto.Name} lvl={dto.Level}");
};
player.Error += ex =>
{
Debug.LogError($"Subscription error [{ex.ErrorCode}]: {ex.Message}");
};
player.Terminated += () =>
{
Debug.LogWarning("Subscription terminated by server");
};Mutate and refresh
player.Update(dto => dto.Level++);
await player.UpdateAsync(dto => dto.Name = "RenamedPlayer");
await player.RefreshAsync();Cancel subscription
if (player is System.IDisposable disposable)
disposable.Dispose();Reconnection note
Connection reconnection is handled by transport state machine (Reconnecting).
For subscription lifecycle, rely on Error/Terminated callbacks and re-bind explicitly when your gameplay flow requires it.
Summary
Data subscriptions are modeled as ISharedEntity<T> objects with live updates (Changed), error/termination signaling, and built-in mutation/refresh helpers.
Last updated on