Skip to main content
Server Logic & Events

Not translated yet — showing English.

Server Events

Your servers push typed events to players; the game listens for them with PlayServEvents.Subscribe<T>. A game server or a cloud function sends an event to a group, and every player in that group gets it over the connection the SDK already keeps open. Events go one way: from your servers to the game.

using System;
using Playserv.Wrapper;
using UnityEngine;

[Serializable]
public class MatchFinished
{
    public string WinnerCallsign;
    public int Score;
}

public sealed class MatchEvents : MonoBehaviour
{
    IDisposable _sub;

    async void Start()
    {
        await PlayServEvents.SubscribeGroupAsync("arena-7");
        _sub = PlayServEvents.Subscribe<MatchFinished>(e => Debug.Log($"{e.WinnerCallsign} wins with {e.Score}"));
    }

    void OnDestroy() => _sub?.Dispose();
}

How delivery works

PartWhat it does
The event typeA plain [Serializable] C# class with public fields. No base class.
The groupA named channel. A player gets events sent to the groups their game joined with SubscribeGroupAsync, and nothing else.
The senderYour game server or cloud function, which sends an event to a group.
The handlerSubscribe<T> picks the events of type T out of everything the game receives.

An event is matched by its type name: the sender names the event type, and the game delivers it to the subscribers of the class with that name. Use the same class name on both sides. The namespace may differ only if no other class the game subscribes to has the same name.

Events aren't stored

An event reaches the players who are in the group when it is sent. A player who joins later, or is offline at that moment, doesn't get it. For state a player must see, use records and send an event only to say something happened.


Subscribe

CallWhat it does
PlayServEvents.Subscribe<T>(handler)Calls handler for every event of type T. Returns an IDisposable: dispose it to stop.
PlayServEvents.SubscribeGroupAsync(name)Joins a group, so its events reach this game.
PlayServEvents.UnsubscribeGroupAsync(name)Leaves a group.

Call them after PlayServ.Connect(): subscribing before the game is connected throws InvalidOperationException. Several handlers of one type share one subscription.

After a reconnect, the SDK joins the game's groups again and keeps its handlers, with no code on your side. Events sent while the game was disconnected are not delivered.

Groups, their names and limits are covered in Groups.


Who sends events

SenderCall
A Unity Dedicated ServerPlayServGameServer.Events.PublishAsync(group, eventType, payload), with the group's project-scoped name, see Groups.
A C# cloud functionPlatform.Publish<T>(group, payload), which uses the C# type's name as the event type.

The game can't send events

PlayServEvents.Publish, PublishForGroup and PublishForUser are in the SDK but always throw PlayServEventPublishingException. So do the Send… helpers the Editor generates for [Event] types. To make something happen for other players, call a function or your game server, and let it send the event.


Limits

WhatLimit
Groups per connection64
Group nameUp to 256 characters, including the project prefix PlayServ adds
Event size1 MiB
Joining or leaving a group10 seconds, then TimeoutException

Errors

ErrorWhen
PlayServGroupSubscriptionExceptionA group join was refused: UnifiedError.SourceCode is group_subscription_limit_reached or group_outside_project. Retrying won't help.
TimeoutExceptionThe platform didn't answer a group join or leave within 10 seconds.
PlayServEventPublishingExceptionThe game tried to send an event.

An event that can't be read as T is logged and dropped; other events keep arriving.


Next steps

Last updated on 22 Oct 2026