question

Ross Klettke avatar image
Ross Klettke asked

PlayFabMultiplayerManager (Party) empty-IEnumerable-send, other unexpected behavior

Using PlayFabMultiplayerManager (Unity) for PlayFabParty -- ran into some unexpected behavior:

  1. Seems that sending an empty IEnumerable (e.g. a List with count 0) sends to all. Initially I expected it to just abandon the send -- sending to no peers.
  2. Also, seems that we can send data to a remote-peer through SendDataMessageToAllPlayers (or using the above way) *before* we get the OnRemotePlayerJoined call for that remote-peer. I expected not to be able to do this.

Psuedo-code on an already-joined player that shows both behaviors:

var welcomedPlayers = new List<PlayFabPlayer>();

private void Update(){
   //sends to all players when welcomedPlayers list is Count 0
   SendDataMessage(someUpdateData, welcomedPlayers, DeliveryOption.Guaranteed);
}

//triggered by PlayFabMultiplayerManager's OnRemotePlayerJoined...
private void OnRemotePlayerJoined(object sender, PlayFabPlayer player){
    SendDataMessage(welcomeData, player, DeliveryOption.Guaranteed);
    welcomedPlayers.Add(player);
}

Causing the resulting output on the newly-joined peer:

got someUpdateData
got someUpdateData
got welcomeData
got someUpdateData

Each of these have a simple solution, but I thought it might be useful to mention them -- both for potentially leading to changes in PlayFabMultiplayerManager and also to help anyone else that might come across the behavior

--Ross

unity3d
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image
Citrus Yan answered

Hi, just had a discussion with the team, the fact is that the behavior of SendDataMessage with an empty player list is the same as SendDataMessageToAllPlayers, which sends messages to all endpoints. Therefore, please make sure that the list is not empty when sending messages to some specific players.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ross Klettke avatar image Ross Klettke commented ·

Yep, the workarounds are easy enough.

I still think it might be a good idea to document these details somewhere (if they aren't already -- I didn't come across them in my readings though)

Thanks,

--Ross

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Ross Klettke commented ·
1 Like 1 ·
Citrus Yan avatar image
Citrus Yan answered

Behavior 2 seems reasonable since SendDataMessageToAllPlayers broadcasts a data message to all players in the current network, it doesn't necessarily need to check whether OnRemotePlayerJoined from the romote peer is triggered or not. However, for behavior 1, based on my inspection on the source code, it shouldn’t be happening. Could you please provide some reproduce steps & code snippets (your implementations) for me to investigate further?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Ross Klettke avatar image
Ross Klettke answered

Probably the easiest way to see behavior1 is to take your HelloPartyLogic example, add a field for:

private List<PlayFabPlayer> _emptyList = new List<PlayFabPlayer>();

and then just alter one line in the update method of your example:

if (Input.GetButtonDown("Fire1")) {

   byte[] requestAsBytes = Encoding.UTF8.GetBytes("Hello (data message)");


  //old line
  //PlayFabMultiplayerManager.Get().SendDataMessageToAllPlayers(requestAsBytes);


   //new line
   PlayFabMultiplayerManager.Get().SendDataMessage(requestAsBytes, _emptyList, DeliveryOption.Guaranteed);

}
  • This odd behavior has been consistent in my testing: Unity 2019.4.12f1, both in Editor and Build, and across multiple devices.
  • Doesn't matter whether the DeliveryOption is Guaranteed or BestEffort

About behavior2 -- the explanation is fine though I still find the behavior unexpected: sending data to a player that locally you aren't aware of yet.

Either way, it might be good to document that behavior somewhere.

--Ross

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Citrus Yan avatar image Citrus Yan commented ·

Thanks for the steps, I will try to reproduce the issue and keep you posted.

1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.