[Unity3D] OnMessage issue with JSON object (SOLVED)

Hi everyone !

I'm working with Unity3D and having an issue with the OnMessage function.

I don't want to send a string but a JSON object.
I actually receive the message but I can't use it in Unity as a System.Object which does not support Indexation.

The following screenshot shows the values in the message received :
0_1525012501636_issue.png

Is there a way to access object datas or future Colyseus updates planned for this kind of issue ?

Thanks.

Hi @Ipsio,

There's actually no JSON being transported from client to server and vice-versa. It's all MessagePack.

This is the major hassle currently with the Unity3D client. It's necessary to cast all data types coming from the server.

You'd need to check which data type is being received and cast e.message to match it. Example:

var message = (IndexedDictionary<string, object>) e.message;
message["id"] // => "T2"

(source: https://github.com/gamestdio/colyseus-unity3d/blob/88b65c42123e726caaa925da36d4314a21d25610/Assets/ColyseusClient.cs#L80)

I'm using the msgpack-unity3d to handle the incoming messages from the server. Maybe there's an easier alternative out there?

Hope this helps. Cheers!

Hi @endel,

thank you for the quick answer.
Indeed, I finally manage to make it work with data casting but I'll take a look at the msgpack !

Thanks a lot !
Bye