Skip to main content

Managing party data

Parties and party members can have custom data stored against them, which can be then be retrieved by other players in the party.

EOS does not supported namespaced party data. The Namespace parameter in all calls should be set as "None" or "Default".

Getting party data

To get data set against the party by the party leader, 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 use GetPartyData:

auto Data = Party->GetPartyData(LocalUserId, PartyId, DefaultPartyDataNamespace);
if (!Data.IsValid())
{
// Party data isn't valid, return error.
return;
}

FVariantData AttributeValue;
if (Data->GetAttribute(TEXT("ExampleAttributeName"), AttributeValue))
{
// AttributeValue now contains the value of the "ExampleAttributeName" attribute.
}

Updating party data

When you retrieve party data from the party subsystem, the returned data is immutable (you can not modify it). Instead to update the data associated with a party, you first need to make a copy of the existing party data, make your changes to the copy, and then pass that to the update call.

caution

Only the party leader can update data on the party itself.

First, use GetPartyData to obtain the party data, and then make a mutable copy of it:

auto ReadOnlyData = Party->GetPartyData(LocalUserId, PartyId, NAME_Default);
if (!ReadOnlyData.IsValid())
{
// Party Data isn't valid, return error.
}
auto PartyData = MakeShared<FOnlinePartyData>(*ReadOnlyData);

To add or set an attribute on the party data, you can call SetAttribute:

PartyData->SetAttribute(
TEXT("ExampleAttributeName"),
TEXT("ExampleAttributeValue"));

To delete an attribute from the party data, you can call RemoveAttribute:

PartyData->RemoveAttribute(TEXT("ExampleAttributeName"));

After you've finished making your changes to the party data, call UpdatePartyData with the new party data:

if (!Party->UpdatePartyData(LocalUserId, PartyId, NAME_Default, *PartyData))
{
// Data didn't set, return error.
}

Getting a party member's data

To get data set against a party member, call GetPartyMemberData with the target user's ID:

auto MemberData = Party->GetPartyMemberData(
LocalUserId,
PartyId,
TargetUserId,
NAME_Default);
if (!MemberData.IsValid())
{
// Member data isn't valid, return error.
return;
}

FVariantData AttributeValue;
if (MemberData->GetAttribute(TEXT("ExampleAttributeName"), AttributeValue))
{
// AttributeValue now contains the value of the "ExampleAttributeName" attribute of the target user.
}

Updating the local user's party member data

caution

A member (including the party leader) can only modify their own member data. They can't change the party member data associated with anyone else.

First, use GetPartyMemberData to obtain your own party member data, and then make a mutable copy of it:

auto ReadOnlyMemberData = Party->GetPartyMemberData(
LocalUserId,
PartyId,
LocalUserId,
NAME_Default);
if (!ReadOnlyMemberData.IsValid())
{
// Member data isn't valid, return error.
return;
}
auto MemberData = MakeShared<FOnlinePartyData>(*ReadOnlyMemberData);

To add or set an attribute on the party member data, you can call SetAttribute:

MemberData->SetAttribute(
TEXT("ExampleAttributeName"),
TEXT("ExampleAttributeValue"));

To delete an attribute from the party member data, you can call RemoveAttribute:

MemberData->RemoveAttribute(TEXT("ExampleAttributeName"));

After you've finished making your changes to the party member data, call UpdatePartyMemberData with the new party data:

if (!Party->UpdatePartyMemberData(
LocalUserId,
PartyId,
NAME_Default,
*MemberData))
{
// Data didn't set, return error.
}