In this guide, we will do a quick rundown of how to create a lobby party with AccelByte. This guide is Unity specific but the flow is identical in any other SDK.

You can grab our SDK from our public GitHub: https://github.com/AccelByte/accelbyte-unity-sdk.

Overview

This guide will focus on implementing Party Lobby using AccelByte SDK for Unity.

Here is the list that is needed for the implementation and later on will be expanded based on each role.

Party actions :

  • CreateParty
  • InviteToParty
  • KickFromParty
  • LeaveParty

Requirements

Before progressing into this guide, you will need to complete the guides below :

Implementations

Create Party

Whoever creates a party will become the party leader, only the party leader can invite other players to the party.

First things first, we need to make sure that the player is already logged-in and in the lobby.

Figure 1. GetLobby from AccelByte plugin

Then create party lobby function along with the callback that contains PartyInfo as it’s parameter. Inside PartyInfo there are PartyID, leaderID, members, invitees and invitationToken.

Figure 2a. CreateParty function
Figure 2b. Callback for CreateParty function

The CreateParty function can also be implemented right after the player presses the “InviteToParty” button in friend list and before calling “InviteToParty” function. It will check if the host/inviter already has a party, if not then create a party.

Invite To Party

The party leader is the only one that can invite other players to the party via their friend list. The party leader can only invite friends who are online.

Figure 3a. The player clicks on party slot button (+) bottom right corner
Figure 3b. The player clicks on Invite to party button

The first step begins with the party leader inviting a player, then the invited player will get the invitation. In this demo game, when the invited user gets the invitation, the game will show a popup invitation.

Figure 4a. InviteToParty function
Figure 4b. InviteToParty callback from FriendPrefab

The callback, OnInviteParty() located in FriendPrefab (created in Friends System) that is assigned for each friend in friend list. On the invited player, there is an event callback that needs to be setup.

Figure 5a. Add a listener to the invitedToParty event
Figure 5b. Remove listener the invitedToParty event

Right after the party leader invite, the invitation should arrive through the invitedToParty event. The PartyInvitation should be cached to a variable so it can be used with the JoinParty function in the next step. The abPartyInfo variable will be used to store information about the party that will be useful to update our UI later on.

Figure 6a. PartyInvitation variable and PartyInfo variable
Figure 6b. OnInvitedToParty callback

The “From” value in PartyInvitation data is a userID, so we need to call GetUserData in order to get the displayname to show to the invited player, then set the popup text and show it on the screen. After the popup is shown to the screen player will be greeted with 2 options, “accept the invitation” or “decline the invitation”.

Figure 7a. Coroutine of ShowPopupPartyInvitation
Figure 7b. PopupInvitation on Unity Scene under Canvas
Figure 7c. Popup party invitation

Decline invitation just closes the popup invitation by calling SetActive to “false” on the popup’s gameobject, however, accepting the invitation will call the JoinParty function and the callback will update the current party with the latest info and also update to UI party slot once the partyInfo is retrieved successfully.

Figure 7d. Assign the AcceptPartyButton OnClick event to OnAcceptPartyClicked
Figure 7e. OnAcceptPartyClicked is called once the accept button is clicked
Figure 7f. Join party callback on the target player

The party slot will show us all the party members from abPartyInfo.members visually. It will record the userId, display name, and email.

The steps are :

  1. Update the abPartyInfo data
  2. ClearPartySlots (makes sure the list will not be stacked up)
  3. Get all the party member display names and email (since we only have the userId from PartyInfo parameter)
  4. The coroutine will wait up until all the party member’s data is collected, and then start updating the party slot UI.
Figure 7g. Party Slots
Figure 7h. Party Slots in Unity Scene:

Those four slots are divided into 2 sections, one PlayerButton (local), and 3 AddFriendButton. The one that we need to be managed is the 3 AddFriendButtons. Reference those 3 buttons with a Transform array to make use of it later.

Figure 7i. PartyMemberButtons array
Figure 7j. Create partyMemberList using PartyData struct
Figure 7k. PartyData Struct
Figure 7l. ClearPartySlots function
Figure 7m. ClearPartyProfile

After the party slot data is cleaned up, we then call GetPartyMemberInfo to get the info that we need to fill in partyMemberList.

Figure 7n. GetPartyMemberInfo Function that calls GetUserByUserId
Figure 7o. Fill in the partyMemberList except for the local player’s entry

Then after all the member’s info collected, the coroutine will start to run RefreshPartySlots() to execute updates on the UI.

Figure 7p. WaitForUpdatedPartyInfo Coroutine updates the UI
Figure 7q. RefreshPartySlots to update each party prefab component located in the partyMemberButtons
Figure 7r. SetupPlayerProfile On PartyPrefab class

This way UI info about the party member will be updated. Right after this, all the party members will receive the JoinedParty event. Just like InvitedToParty, for this event, we need to set up the listener.

Figure 8a. Add Listener to JoinedParty Event
Figure 8b. Remove Listener from JoinedParty event

The OnMemberJoinedParty function does some update to the party info variable in the AccelbyteLobbyLogic and updates to UI party slot once the partyInfo is retrieved successfully.

Figure 9a. OnMemberJoinedParty notification
Figure 9b. GetPartyInfoHelper function
Figure 9c. Callback from PartyInfo update

Kick From Party

The ability to kick from party is also one of Party Leader’s available actions. The party leader can kick one of the party members and then kicked player will leave the party after receiving the kick notification.

Figure 10a. Kick From Party button

By hovering over the party slot button, the player profile popup will appear, the kick from party button is available here. This is part of PopupPartyControl as the party leader you can kick a party member and leave the party, as a member you can only leave the party. Figure 10b is showing the scene of the popup.

Figure 10b PopupPartyControl in the Unity scene

There are a few grouped game objects such as :

  • LocalLeaderCommand (will be shown when the playerButton triggers the onMouseHover event on Figure 7h, when the local player is a party leader),
  • LocalMemberCommand (will be shown when the playerButton triggers the onMouseHover event on Figure 7h, when the local player is a party member), and
  • MemberCommand (will be shown when any of AddFriendButton triggers the onMouseHover event on Figure 7h, when the local player is a party leader).
Figure 10c PopupPartyControl in code

On the memberCommand gameObject, add a listener for the kickFromParty button to kick each userId registered to each PartyPrefab.

Figure 11a. OnKickFromPartyClicked function
Figure 11b. KickPartyMember is calling AccelByte’s KickPartyMember
Figure 11c. OnKickPartyMember callback from KickPartyMember

The kicked player will receive KickedFromParty Notification right after being kicked by the party leader. The callback of this event will be used for updating/clearing the party slot.

Figure 12a. Register KickedFromParty as the listener
Figure 12b. Remove the listener of KickedFromParty
Figure 12c. Clearing party slot on callback KickedFromParty

All the other members will be getting LeaveFromParty event as the result of this action to update the PartyInfo and the UI party slot to the newest info where the kicked player is already gone.

Figure 13a. LeaveFromParty event registration
Figure 13b. Remove listener away after use
Figure 13c. Update PartyInfo and update the party slots

Leave From Party

Figure 14. Leave action as a party leader

This action can be used by every member including the party leader. A member will be calling LeaveParty function and the other members will be getting the LeaveFromParty event just like kick from party section.

Figure 15. Leave party action from a party member

Here is the leave party function that is available on a party slot profile popup, which will call the AccelByte LeaveParty function. Right after that, the callback function clears the party slots, marking that they left the party.

Figure 16a. OnLeavePartyButtonClicked assigned to Leave Party button
Figure 16b. Accelbyte’s LeaveParty function
Figure 16c. Clear party slots after leaving the party

Right after getting the event, all the remaining members will have to update their PartyInfo and their UI party slot as can be seen in Figures 13a, 13b and 13c on Kick From Party Section. If the one that leaves the party is party leader, the leader title will be transferred to the second player on the PartyInfo.members[] list.

That just about covers it for the Lobby feature. While this guide highlights what is available in our out of the box feature set, it is important to note that we can customize the platform to match your exact needs, from small changes to complete, bespoke features.

No two games are the same and we believe it is important to tailor our services to match each individual customer’s needs.

Please reach out to us at support@accelbyte.io if you have any questions.