Not getting updated state in Unity client

I'm only getting the first state and it's not being updated beyond that.
Is there something obvious that I'm not seeing that is causing the issue?

Here is my room code:

import BaseRoom from "./BaseRoom";
import {Client} from "colyseus";

export class State {
    ticks: number;
    constructor() {
        this.ticks = 0;

export default class ChatRoom extends BaseRoom<State> {
    onDispose(): void | Promise<any> {
        return undefined;

    onInit(options: any): void {
        console.log('ChatRoom created');
        this.setState(new State());
        setInterval(() => {
            this.setState({ticks: this.state.ticks + 1});
            console.log('Updated state', this.state);
        }, 1000);

    onJoin(client: Client, options?: any, auth?: any): void | Promise<any> {
        return undefined;

    onLeave(client: Client): void | Promise<any> {
        return undefined;

    onMessage(client: Client, data: any): void {
        console.log('ChatRoom received message', data);

And on the Unity Side:

    Client client = new Colyseus.Client("ws://localhost:6900");
    client.OnError += Client_OnError;
    yield return StartCoroutine(client.Connect());
    Room room = client.Join("chat", new Dictionary<string, object>() {
        {"username", username}
    room.OnReadyToConnect += (sender, e) => {
        Debug.Log("Ready to join room");

    room.OnError += Room_OnError;

    room.OnStateChange += OnStateChange;
    room.Listen("message", this.OnMessage);
    room.Listen("ticks", this.OnTick);
    room.OnJoin += Room_OnJoin;
    room.OnMessage += Room_OnMessage;

    int i = 0;

    while (true)


        if (i % 50 == 0)

        yield return 0;

Hey @imallic,

The the setState() method actually will overwrite the state - it doesn't work like React does. You'd usually mutate the state instead:


Hope this helps!

That solved the issue. You are correct, I was taking a React approach to it.
Thanks for saving me again @endel!

This may be off topic, but does colyseus support UDP? with state changes?

@imallic You're welcome <3

Maybe in the future! I'm currently working on TCP support to create a Game Maker client (they don't support WebSocket neither UDP)

It would need to be some sort of Reliable UDP, though. I'm still not sure how to go about it, since the order of messages are important.


But things like updating player movement wouldn't need to be that reliable. I understand that things like interpolation could be used but it's still going to make something like an FPS too glitchy.

I have the same issue, I didn't get an updated state on the unity side whether colyseus monitor shows the updated data. So, new patches are not received by the unity client. Here is my code.

    private void OnPlayerAdd(string key, Player newPlayer){

    if (!playersToAdd.ContainsKey(
        playersToAdd.Add(, newPlayer);

        if (newPlayer.Seatnumber != -1 && == SessionId)
           BoardManager.Instance.Set_up_profile(false, newPlayer.Seatnumber, playersToAdd[]);

    if ( == SessionId && newPlayer.Seatnumber != -1)
        thisSeat = newPlayer.Seatnumber;

    if (GameplayRoom.State.players.Count >= 2)
    newPlayer.PlayerState.OnChange += changes =>
        Debug.Log("-=-=-=-=-=-=-=-=-=-=-=-=-Player Log=-=--=-=-=-=-=-> " + key + " " +;
        foreach (var t in changes)
            Debug.Log(t.Field + " " + t.Value);

this is the code I have set on the client side
and This function is subscribe in "GameplayRoom.State.players.OnAdd += OnPlayerAdd;"