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>() {
        {"accessToken",accessToken},
        {"username", username}
    });
    room.OnReadyToConnect += (sender, e) => {
        Debug.Log("Ready to join room");
        StartCoroutine(room.Connect());
    };

    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)
    {
        client.Recv();

        i++;

        if (i % 50 == 0)
        {
            room.Send("some_command");
        }

        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:

this.state.ticks++;

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.

Cheers!

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){
    newPlayer.TriggerAll();
    newPlayer.PlayerState.TriggerAll();

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

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

    if (newPlayer.id == SessionId && newPlayer.Seatnumber != -1)
    {
        thisSeat = newPlayer.Seatnumber;
        BoardManager.Instance.Rearrange_Seat();
    }

    if (GameplayRoom.State.players.Count >= 2)
    {
        BoardManager.Instance.WaitingTextDisable(false);
    }
    newPlayer.PlayerState.OnChange += changes =>
    {
        Debug.Log("-=-=-=-=-=-=-=-=-=-=-=-=-Player Log=-=--=-=-=-=-=-> " + key + " " + newPlayer.id);
        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;"