- Home /
Problem sending serialized data with Play Games Platform
Hello. I am having a problem with Google Play Games platform in real time multiplayer API. The definition for sending a message to all people in the room is:
PlayGamesPlatform.Instance.RealTime.SendMessageToAll(reliable, message);
Where message is a byte[]. So I want to serialize a class or an object and send it with this method. I serialize like this:
public static byte[] Byte_ConvertObjectToBinary(float obj)
{
MemoryStream o = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(o, obj);
return o.GetBuffer();
}
If I serialize and send just a float, for example transform.position.y
everything works fine. On my listener I wait for the event to be fired and I deserialize the byte[] and get my float. But I want to do something more complex, for example to serialize "something" where I can tell that the float I am sending is actually a transform.position. I have tried serializing a HashTable and a custom public class but always when I run my project my app crashes. And the problem is that it crashes with no debug info, no one. Just "user unexpectedly disconnected". For instance, I am using adb logcat -s Unity
to debug in my emulator. The question here is, is there any limit on the size I can send in a byte array with the Api? Is there something am I missing? Which could be another way to send messages with information and some kind of identification to know what kind of property am I receiving in my listener provided that we can only send byte[] with Google Api?
I was so surprised I couldn't send a serialized Hashtable with just a pair of key - value. This was my code for serializing the Hashtable:
private static byte[] Byte_ConvertObjectToBinary_FromHashtable(Hashtable obj)
{
MemoryStream o = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(o, obj);
return o.ToArray();
}
And the app crashes always. I didn't know if was crashing because of the serialization, deserialization or sending it. But it seems to be a problem when I call PlayGamesPlatform.Instance.RealTime.SendMessageToAll(reliable, message);
so the problem is sending the data.
Thank you all!