GitHub Documentation

State Sync change in objects

  • Hi! I'm still a bit new to colyseus, so I apologize if this question might sound dumb:

    I'm trying to synchronize my server and client's state with an object

        key: {}

    On the server, I have a piece of logic that handles messages from the client and modify the entire object, key.

    When listening for changes on the client, nothing comes up:'key', change => {
        console.log('key state has changed');

    unless I do:'key/:id', change => {
        console.log('key state has changed');

    But, I don't want individual attributes of the object that changed. I want the entire object.

    Unless the whole point of state sync is to synchronize small changes, then would I just broadcast the new Key Object as a work around?

    Any help or suggestions would be greatly appreciated!

  • administrator

    Hi @zzmarkzz321, that's correct! The client will receive each single change you've made from the server-side.

    You can catch all the properties by using:

    // client-side'key/:attribute', change => {
        console.log(change.path.attribute, "has changed to", change.value);

    If you'd like to send the whole object directly, you can broadcast it from the server:

    // server-side

    And catch it using onMessage signal: => {
      console.log("here's the new object:", message);

  • @endel Wow thanks so much for the quick and helpful response! Looking forward to diving deeper into the framework :)


© 2021 Lucid Sight, Inc