<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Not getting updated state in Unity client]]></title><description><![CDATA[<p>I'm only getting the first state and it's not being updated beyond that.<br />
Is there something obvious that I'm not seeing that is causing the issue?</p>
<p>Here is my room code:</p>
<pre><code>import BaseRoom from &quot;./BaseRoom&quot;;
import {Client} from &quot;colyseus&quot;;

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

export default class ChatRoom extends BaseRoom&lt;State&gt; {
    onDispose(): void | Promise&lt;any&gt; {
        return undefined;
    }

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

    onJoin(client: Client, options?: any, auth?: any): void | Promise&lt;any&gt; {
        return undefined;
    }

    onLeave(client: Client): void | Promise&lt;any&gt; {
        return undefined;
    }

    onMessage(client: Client, data: any): void {
        console.log('ChatRoom received message', data);
    }
}
</code></pre>
<p>And on the Unity Side:</p>
<pre><code>    Client client = new Colyseus.Client(&quot;ws://localhost:6900&quot;);
    client.OnError += Client_OnError;
    yield return StartCoroutine(client.Connect());
    Room room = client.Join(&quot;chat&quot;, new Dictionary&lt;string, object&gt;() {
        {&quot;accessToken&quot;,accessToken},
        {&quot;username&quot;, username}
    });
    room.OnReadyToConnect += (sender, e) =&gt; {
        Debug.Log(&quot;Ready to join room&quot;);
        StartCoroutine(room.Connect());
    };

    room.OnError += Room_OnError;

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

    int i = 0;

    while (true)
    {
        client.Recv();

        i++;

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

        yield return 0;
    }</code></pre>
]]></description><link>http://discuss.colyseus.io/topic/89/not-getting-updated-state-in-unity-client</link><generator>RSS for Node</generator><lastBuildDate>Thu, 18 Jun 2026 07:52:08 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/89.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 06 Jun 2018 00:22:46 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Not getting updated state in Unity client on Sat, 17 Dec 2022 09:48:00 GMT]]></title><description><![CDATA[<p>I'm only getting the first state and it's not being updated beyond that.<br />
Is there something obvious that I'm not seeing that is causing the issue?</p>
<p>Here is my room code:</p>
<pre><code>import BaseRoom from &quot;./BaseRoom&quot;;
import {Client} from &quot;colyseus&quot;;

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

export default class ChatRoom extends BaseRoom&lt;State&gt; {
    onDispose(): void | Promise&lt;any&gt; {
        return undefined;
    }

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

    onJoin(client: Client, options?: any, auth?: any): void | Promise&lt;any&gt; {
        return undefined;
    }

    onLeave(client: Client): void | Promise&lt;any&gt; {
        return undefined;
    }

    onMessage(client: Client, data: any): void {
        console.log('ChatRoom received message', data);
    }
}
</code></pre>
<p>And on the Unity Side:</p>
<pre><code>    Client client = new Colyseus.Client(&quot;ws://localhost:6900&quot;);
    client.OnError += Client_OnError;
    yield return StartCoroutine(client.Connect());
    Room room = client.Join(&quot;chat&quot;, new Dictionary&lt;string, object&gt;() {
        {&quot;accessToken&quot;,accessToken},
        {&quot;username&quot;, username}
    });
    room.OnReadyToConnect += (sender, e) =&gt; {
        Debug.Log(&quot;Ready to join room&quot;);
        StartCoroutine(room.Connect());
    };

    room.OnError += Room_OnError;

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

    int i = 0;

    while (true)
    {
        client.Recv();

        i++;

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

        yield return 0;
    }</code></pre>
]]></description><link>http://discuss.colyseus.io/post/279</link><guid isPermaLink="true">http://discuss.colyseus.io/post/279</guid><dc:creator><![CDATA[Imallic]]></dc:creator><pubDate>Sat, 17 Dec 2022 09:48:00 GMT</pubDate></item><item><title><![CDATA[Reply to Not getting updated state in Unity client on Invalid Date]]></title><description><![CDATA[<p>Hey <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/88">@imallic</a>,</p>
<p>The the <code>setState()</code> method actually will overwrite the state - it doesn't work like React does. You'd usually mutate the state instead:</p>
<pre><code>this.state.ticks++;
</code></pre>
<p>Hope this helps!</p>
]]></description><link>http://discuss.colyseus.io/post/280</link><guid isPermaLink="true">http://discuss.colyseus.io/post/280</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Not getting updated state in Unity client on Invalid Date]]></title><description><![CDATA[<p>That solved the issue. You are correct, I was taking a React approach to it.<br />
Thanks for saving me again <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/1">@endel</a>!</p>
]]></description><link>http://discuss.colyseus.io/post/281</link><guid isPermaLink="true">http://discuss.colyseus.io/post/281</guid><dc:creator><![CDATA[Imallic]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Not getting updated state in Unity client on Invalid Date]]></title><description><![CDATA[<p>This may be off topic, but does colyseus support UDP? with state changes?</p>
]]></description><link>http://discuss.colyseus.io/post/282</link><guid isPermaLink="true">http://discuss.colyseus.io/post/282</guid><dc:creator><![CDATA[Imallic]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Not getting updated state in Unity client on Invalid Date]]></title><description><![CDATA[<p><a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/88">@imallic</a> You're welcome &lt;3</p>
<p>Maybe in the future! I'm currently working on TCP support to create a Game Maker client (they don't support WebSocket neither UDP)</p>
<p>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.</p>
<p>Cheers!</p>
]]></description><link>http://discuss.colyseus.io/post/283</link><guid isPermaLink="true">http://discuss.colyseus.io/post/283</guid><dc:creator><![CDATA[endel]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Not getting updated state in Unity client on Invalid Date]]></title><description><![CDATA[<p>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.</p>
]]></description><link>http://discuss.colyseus.io/post/284</link><guid isPermaLink="true">http://discuss.colyseus.io/post/284</guid><dc:creator><![CDATA[Imallic]]></dc:creator><pubDate>Invalid Date</pubDate></item><item><title><![CDATA[Reply to Not getting updated state in Unity client on Fri, 16 Dec 2022 11:23:39 GMT]]></title><description><![CDATA[<p>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.</p>
<pre><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 &amp;&amp; newPlayer.id == SessionId)
        {
           BoardManager.Instance.Enable_Disable(false);
           BoardManager.Instance.Set_up_profile(false, newPlayer.Seatnumber, playersToAdd[newPlayer.id]);
        }
    }

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

    if (GameplayRoom.State.players.Count &gt;= 2)
    {
        BoardManager.Instance.WaitingTextDisable(false);
    }
    newPlayer.PlayerState.OnChange += changes =&gt;
    {
        Debug.Log(&quot;-=-=-=-=-=-=-=-=-=-=-=-=-Player Log=-=--=-=-=-=-=-&gt; &quot; + key + &quot; &quot; + newPlayer.id);
        foreach (var t in changes)
        {
            Debug.Log(t.Field + &quot; &quot; + t.Value);
        }
    };
}
</code></pre>
<p>this is the code I have set on the client side<br />
and This function is subscribe in &quot;GameplayRoom.State.players.OnAdd += OnPlayerAdd;&quot;</p>
]]></description><link>http://discuss.colyseus.io/post/2282</link><guid isPermaLink="true">http://discuss.colyseus.io/post/2282</guid><dc:creator><![CDATA[dayna chandera]]></dc:creator><pubDate>Fri, 16 Dec 2022 11:23:39 GMT</pubDate></item></channel></rss>