Skip to main content

Updating statistics

In order to use achievements and leaderboards in Epic Online Services, you need to upload stat data.

Uploading stats to EOS

To send statistics for a user, use the UpdateStats function on the stats interface:

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

// ...

IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
IOnlineStatsPtr StatsInterface = Subsystem->GetStatsInterface();

FOnlineStatsUserUpdatedStats Stat = FOnlineStatsUserUpdatedStats(Identity->GetUniquePlayerId(0).ToSharedRef());

// For each of the stats to upload, provide the StatName (matching what
// is defined in the Epic Online Services portal) and the int32 value.
// The EOnlineStatModificationType is ignored, as the stat type is defined
// in the portal.
//
// You can add multiple entries to the Stats property to send more than one
// stat value in a single request.
Stat.Stats.Add(StatName, FOnlineStatUpdate(IngestAmount, FOnlineStatUpdate::EOnlineStatModificationType::Unknown));

TArray<FOnlineStatsUserUpdatedStats> Stats;
Stats.Add(Stat);

StatsInterface->UpdateStats(
Identity->GetUniquePlayerId(0).ToSharedRef(),
Stats,
FOnlineStatsUpdateStatsComplete::CreateLambda([](
const FOnlineError &ResultState)
{
// Check `ResultState.bSucceeded`.
}));