Push channels in CloudBehaviours
Declare a push channel, listen for it in your game, and understand how delivery works.
Read time 2 minutesLast updated 15 days ago
A public event on a CloudBehaviour becomes a push channel. When the cloud class invokes the event, Cloud Code sends a message to every player in the session (or, for a -scoped CloudBehaviour, to that player), and the generated client bindings raise a matching . Use a push channel to notify players the moment something happens, such as a turn ending, without polling.
PlayerUnityEventPush channels carry notifications and payloads. To share state that a client can read at any time, use synchronized state instead.
Declare a push channel
A public event of type , , , or becomes a push channel:
ActionAction<T>EventHandlerEventHandler<T>[StateScope(Scope.MultiplayerSession)]public class MatchState : CloudBehaviour{ public int Round; public event Action<string> RoundEnded; public void PlayTurn() { Round++; RoundEnded?.Invoke(Context.PlayerId); }}
Event payloads serialize as JSON, and event payloads are limited to four parameters.
Listen for push channel events in your game
The generated client bindings expose each push channel as a . Subscribe with :
UnityEventAddListenerprotected virtual void OnEnable(){ EnableClient(); matchStateClient.RoundEnded.AddListener(playerId => Debug.Log($"Round ended by {playerId}"));}
Because the binding exposes push channels as s, you can also wire up listeners in the Inspector window.
UnityEventDelivery
Only connected clients receive a push message. Push channels are transient: they aren't stored or replayed for a player who connects later. Represent lasting state as synchronized state instead.
Every player in the session receives an event you raise, whatever its payload. To send private data to one player, such as revealing which card a player drew, use instead of an event. For shaping what a specific player sees in synchronized state, refer to Per-player state views in CloudBehaviours.
Push.SendPlayerMessageAsync(Context, message, messageType, playerId)