Skip to main content

Viewing party members

Once you're a member of a party, you can retrieve a list of party members and check if you're the party leader.

Get a list of party members

First, get the online party interface:

#include "OnlineSubsystem.h"
#include "OnlineSubsystemUtils.h"
#include "Interfaces/OnlinePartyInterface.h"

// ...

IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlinePartyPtr Party = Subsystem->GetPartyInterface();

If you need to get a list of all the parties you're currently in, you can use GetJoinedParties:

TArray<TSharedRef<const FOnlinePartyId>> Results;
if (!Party->GetJoinedParties(
*Identity->GetUniquePlayerId(0).Get(), // The local user ID to get parties for.
Results))
{
return TArray<UDemoPartyId *>();
}

// Iterate through Results to see all the joined parties.

Once you have a party ID (a TSharedRef<const FOnlinePartyId>), you can view the members of the party:

TArray<FOnlinePartyMemberConstRef> PartyMembers;
if (!Party->GetPartyMembers(
*Identity->GetUniquePlayerId(0).Get(), // The local user ID that is already a member
// of the party.
*PartyId->PartyId.Get(), // The party ID.
PartyMembers))
{
return TArray<UDemoPartyMemberId *>();
}

// Iterate through PartyMembers to access the list of party members.

Checking who the party leader is

Only the party leader can perform actions like kicking party members or updating party-wide metadata. Initially, the player that creates the party will be the party leader, but this will change if the party leader leaves the party or actively promotes someone else to be the leader through PromoteMember.

You can check each member of the party to see if they're the party leader using the IsMemberLeader function:

Party->IsMemberLeader(
*Identity->GetUniquePlayerId(0).Get(), // The user that is performing the check.
*PartyId->PartyId.Get(), // The party ID.
*Identity->GetUniquePlayerId(0).Get() // The ID of the member to get the leader status of.
);