Crazy lag on Unity Client while trying to deserialize MsgPack data. Issue with patching. (SOLVED)

I have been developing a small game using Unity as the client. I downloaded your source code and it was working until I put about 400 world objects down. These objects do not move or update at all.

Now, when the player moves, there are huge lag spikes. I narrowed it down to line 180 in Room.cs (Patch function):

var newState = MsgPack.Deserialize<IndexedDictionary<string, object>> (new MemoryStream(this._previousState));

I believe this is because any time there is an update, it attempts to deserialize the entire state, when it only needs to actually deserialize the difference and apply it.

Does anyone have any ideas on how to fix this?

The only solution I can think of would be to have a different room for the static world objects so that they would not need to get serialized for every patch... this seems like a bit of a hack though.

I do realize it is expensive to load the world from the server, but I would like the world to be randomly generated and then sent to the player as they load sections. Is this possible with Colyseus?

Hi @diericx,

I see! Thanks for taking your time to report this.

One thing you can do is storing the world objects outside the room's state, and send it directly to the client when he joins the room. e.g.

onInit () { = createWorldObjects();

onJoin (client, options) {

You'll receive the data in your OnData handler in the client-side.

Hope this helps!

@endel Worked perfectly!! Thank you so much man, this is really cool.