question

Evan Maxey avatar image
Evan Maxey asked

How to detect disconnect from lobby on client quit

Using Unity SDK. Use Case: A user is invited to the lobby and successfully joins. The user, now a member, leaves the lobby via Lobby.Leave(entKey), where the entKey is for the member leaving the lobby.

What notification is provide to the lobby, lobby owner, and lobby members?

PlayfabMultiplayerEventProcessor is in place I have subscribed to all available events, "OnLobby..." No events are fired when the member leaves.

I have validated events fire for other lobby actions. The member that left the lobby receives OnLobbyDisconnected as expected.

apis
10 |1200

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

Neils Shi avatar image
Neils Shi answered

After my testing, when the lobby member leaves the lobby through the Lobby.Leave() method, the PlayFabMultiplayer.OnLobbyMemberRemoved event will be triggered, you may refer to my testing code below. In addition, have you followed https://learn.microsoft.com/en-us/gaming/playfab/features/multiplayer/lobby/lobby-matchmaking-sdks/multiplayer-unity-plugin-quickstart#set-up-your-scene to set up the scene (which you need to drag and drop the PlayfabMultiplayerEventProcessor into your scene in the Hierarchy window)?

 PlayFabMultiplayer.OnLobbyMemberRemoved += this.PlayFabMultiplayer_OnMemberLeft;
    
 private void PlayFabMultiplayer_OnMemberLeft(Lobby lobby, PFEntityKey member, LobbyMemberRemovedReason reason)
     {
         Debug.Log("A member has left:"+member.Id);
     }
10 |1200

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

Neils Shi avatar image
Neils Shi answered

It looks like you are using Playfab Lobby and Matchmaking SDKs, and when a player leaves the lobby, the PlayFabMultiplayer.OnLobbyMemberRemoved event will be triggered. You can implement the notification feature based on it. For more info, you can refer to https://learn.microsoft.com/en-us/gaming/playfab/features/multiplayer/lobby/unity-multiplayer-api-reference/playfab.multiplayer/playfabmultiplayer/onlobbymemberremoved .

10 |1200

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

Evan Maxey avatar image
Evan Maxey answered

@Neils Shi Hi Neils - thanks for the reply. The player is leaving the lobby via Lobby.Leave(entKey). They are not removed.

That clarified, I am listening for PlayFabMultiplayer.OnLobbyMemberRemoved and it does not fire when the member client uses Lobby.Leave.

How is the lobby or lobby owner notified that the member left?

10 |1200

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

Evan Maxey avatar image
Evan Maxey answered

@neils Shi Hi Neils, appreciate you taking a look here. I do have the setup done per the "set up your scene" link you provided including PlayfabMultiplayerEventProcessor in the scene. Other events do fire so I do know that's working. I will make sure I have the latest versions of everything and see what I get from OnLobbyMemberRemoved. I am listening for that event and did not see if firing previously.

10 |1200

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

Evan Maxey avatar image
Evan Maxey answered

@Neils Shi Hi Neils - great news, after upgrading all playfab components OnLobbyMemberRemoved is firing as expected and all lobby members are seeing the event. Once again I sincerely appreciate your help!

10 |1200

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

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.