How do you send more than one data in Shared AR?

Include the following details (edit as applicable):

  • Issue category: Multiplayer
  • Device type & OS version: Android
  • Host machine & OS version: Windows
  • Issue Environment :
  • Xcode version:
  • ARDK version: 2.5.1
  • Unity version: 2021.3

Description of the issue:
private void OnDidReceiveDataFromPeer(PeerDataReceivedArgs args)
{
var data = args.CopyData();
switch ((_MessageType)args.Tag)
{

    case _MessageType.BallPositionMessage:
      _controller.SetBallSpeed(DeserializeFloat(data));
      break;

    default:
      throw new ArgumentException("Received unknown tag from message");
  }
}

In the code snippet above, I need to pass 2 data inside “_controller.SetBallSpeed(DeserializeFloat(data));”

meaning, the code should look something like
“_controller.SetBallSpeed(DeserializeFloat(data1),DeserializeFloat(data2));”

I am aware you need to create a new “DeserializeFloat”

private float DeserializeFloat(byte launchSpeed)
{
using (var readingStream = new MemoryStream(launchSpeed))
using (var binaryDeserializer = new BinaryDeserializer(readingStream))
return FloatSerializer.Instance.Deserialize(binaryDeserializer);
}

How can I do this in the OnDidReceiveDataFromPeer()?

Pardon me for the long code snippet.

Hello Peng,

Thanks for your patience. Also a quick note that I saw your questions on Discord as well and the Bot has since been fixed. If you prefer Discord you’re able to use it again.

As for your question. So unfortunately we don’t have a Float Array Deserializer but I can think of two different ways you can approach this. Here is a link to the Deserializers we have.

The simplest approach is probably to use our Vector2 serializer so you can put in your two float values in a Vector2 and then after getting deserialized just pull them out into individual float values.

This one is a bit more complicated but you can treat both your values as just a byte array which would mean converting them into an array of bytes. Since Floats are 32 bits, you’ll have a byte array of 8 bytes, the first four are the first number and the last four are the second number but you would need to create the bit manipulation that would fill the array and split the values back out as two floats.