Skip to main content

Inviting players and joining parties

To join a party, you first need an invite. Invites can be sent by members of a party.

warning

If an invite is successfully sent from one player to another over the local platform (such as a Steam player sending an invite to another Steam player), the invite will not also be sent over Epic Online Services.

This is to prevent the receiving user from receiving duplicate invite notifications.

Some platforms such as Steam do not provide an API for implementing OnPartyInviteReceivedEx. Therefore, when a Steam player sends a party invite to another Steam player, and the invite is successfully sent over Steam, your game will not see the OnPartyInviteReceivedEx event nor will the invite be visible through GetPendingInvites. On Steam, you will only receive party invitation events in-game when the invite was sent from a non-Steam player, such as someone playing on the Epic Games Store or console.

Sending an invitation

To send an invite to a player, you need their unique net ID. You can retrieve such IDs from the friends list.

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();

Then send the invitation to the target player:

// In this example, Friend is an FOnlineFriend retrieved from
// the friends interface, but you can send invites to any unique net ID.
FPartyInvitationRecipient Recipient = FPartyInvitationRecipient(Friend->Friend->GetUserId());

// Send the invitation.
if (!Party->SendInvitation(
*Identity->GetUniquePlayerId(0).Get(), // The ID of the player sending the invite.
*PartyId->PartyId, // The party to invite the target player to.
Recipient,
FOnSendPartyInvitationComplete::CreateLambda([](
const FUniqueNetId &LocalUserId,
const FOnlinePartyId &PartyId,
const FUniqueNetId &RecipientId,
const ESendPartyInvitationCompletionResult Result) {
// If Result == ESendPartyInvitationCompletionResult::Succeeded,
// the invitation was sent successfully.
})))
{
// Call didn't start, return error.
}

Listening for invites

Invitation list

On the receiving side, you need to be listening for when invites are sent to you. There are two events for doing this: OnPartyInvitesChanged and OnPartyInviteReceived. Which one you use depends on what you're doing in response to the event.

If you're showing a persistent list of invitations with GetPendingInvites, you'll want to listen for OnPartyInvitesChanged, as this event will fire whenever an invite is added or removed.

You can listen to this event like so:

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

Party->AddOnPartyInvitesChangedDelegate_Handle(
FOnPartyInvitesChangedDelegate::CreateUObject(this, &UMyClass::OnPartyInvitesChanged));

// ...

void UMyClass::OnPartyInvitesChanged(const FUniqueNetId &LocalUserId)
{
// Call GetPendingInvites at some point here and refresh the list.
}

Pop-up notifications

If you're showing pop-up notifications in your game, you'll want to use OnPartyInviteReceivedEx and show the pop-up in response to this event.

You can listen to this event like so:

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

Party->AddOnPartyInviteReceivedExDelegate_Handle(
FOnPartyInviteReceivedExDelegate::CreateUObject(this, &UMyClass::OnPartyInviteReceived));

// ...

void UMyClass::OnPartyInviteReceived(
const FUniqueNetId &LocalUserId,
const IOnlinePartyJoinInfo &Invitation)
{
// Access invitation data through 'Invitation'.
}

Joining a party

Once you have an invitation, you'll can either join the party or reject the invitation (with RejectInvitation). Joining a party requires an IOnlinePartyJoinInfo, which you can get from GetPendingInvites.

To join a party, use the JoinParty method:

// Party is the party interface retrieved from GetPartyInterface.

if (!Party->JoinParty(
*Identity->GetUniquePlayerId(0).Get(),
*Invite->PartyInvite,
FOnJoinPartyComplete::CreateLambda([](
const FUniqueNetId &LocalUserId,
const FOnlinePartyId &PartyId,
const EJoinPartyCompletionResult Result,
const int32 NotApprovedReason) {
// If Result == EJoinPartyCompletionResult::Succeeded, the party
// was joined successfully, and you can now access the party with
// the GetParty and GetJoinedParties functions.
})))
{
// Call didn't start, return error.
}

Listening for party join and exit events

It is important to listen for party join and exit events, since your players might join parties via the Epic Social Overlay. When a player joins a party via the overlay, the party system will automatically leave the current presence party (if there is one) and join the new party.

To listen for these events, register the appropriate event handlers:

Party->AddOnPartyJoinedDelegate_Handle(
FOnPartyJoinedDelegate::CreateLambda([](
const FUniqueNetId& LocalUserId, // The local player that joined the party.
const FOnlinePartyId& PartyId // The party that was joined.
) {
// Handle the party being joined.
}));

Party->AddOnPartyExitedDelegate_Handle(
FOnPartyExitedDelegate::CreateLambda([](
const FUniqueNetId& LocalUserId, // The local player that left the party.
const FOnlinePartyId& PartyId // The party that was left.
) {
// Handle the party being left.
}));