I am trying to send Microsoft's Kinect v2 body data over MQTT to effectively map skeletal data without direct connection to the Kinect, but I can't seem to deserialize a Body[] correctly. I am publishing the a list of Bodys every frame in Update().
My current setup is using Newtonsoft's JSON.Net to serialize a List taken from Body[] and publish it to MQTT (using https://github.com/vovacooper/Unity3d_MQTT). I used this since the Body class isn't serializable (so I can't use JSONUtility?).
Essentially I have:
void Update() {
...
//trackedBodies is a List<Body> that contains the tracked Bodys
//client is MQTTClient that is connected
string bodyData = JsonConvert.SerializeObject(trackedBodies);
client.Publish("test", System.Text.Encoding.UTF8.GetBytes(bodyData));
...
}
And:
void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e) {
//Check MQTT for data, then deserialize
List<Body> bodyData = JsonConvert.DeserializeObject<List<Body>>(System.Text.Encoding.UTF8.GetString(e.Message));
Debug.Log(bodyData);
}
When the List is empty, I am able to receive an empty List of Bodys. When it is nonempty, the code halts for that method, and I am no longer able to receive messages at all. The Update() method still works properly.
I would appreciate it if anybody knows how to help with what I currently have, or suggest a better alternative to my problem.