Skip to main content

Retrieving entitlements

E-commerce functionality is provided via the IOnlineStoreV2, IOnlineEntitlements and IOnlinePurchase interfaces. Retrieving the owned entitlements is done via the IOnlineEntitlements interface.

Platform support​

For Steam users, entitlements include both owned DLC and inventory items in the user's Steam inventory.

Querying a list of entitlements​

To query for entitlements, first get the online entitlements interface:

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

// ...

IOnlineSubsystem* Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineEntitlementsPtr Entitlements = Subsystem->GetEntitlementsInterface();

Register the event handler so you know when the entitlements have been queried. QueryEntitlementsCompleteDelegateHandle is declared as an FDelegateHandle.

this->QueryEntitlementsCompleteDelegateHandle =
Entitlements->AddOnQueryEntitlementsCompleteDelegate_Handle(
FOnQueryEntitlementsComplete::FDelegate::CreateUObject(
this, &UMyClass::HandleQueryEntitlementsComplete));

Then call QueryEntitlements to cache all of the user's current entitlements.

Entitlements->QueryEntitlements(
*Identity->GetUniquePlayerId(0).Get(), // The local player to get entitlements for.
TEXT(""));

When your callback fires, you'll want to handle any errors and then deregister the event handler:

void UMyClass::HandleQueryEntitlementsComplete(
bool bWasSuccessful,
const FUniqueNetId& UserId,
const FString& Namespace,
const FString& Error)
{
// Deregister the event handler.
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineEntitlementsPtr Entitlements = Subsystem->GetEntitlementsInterface();
Entitlements->ClearOnQueryEntitlementsCompleteDelegate_Handle(this->QueryEntitlementsCompleteDelegateHandle);
this->QueryEntitlementsCompleteDelegateHandle.Reset();

// Get the entitlements if they were successfully queried.
if (bWasSuccessful)
{
TArray<TSharedRef<FOnlineEntitlement>> UserEntitlements;
Entitlements->GetAllEntitlements(
UserId,
Namespace,
UserEntitlements);

// UserEntitlements now contains the user's entitlements.
}
}

Consuming an entitlement​

Refer to Purchasing offers on how to consume entitlements. The process for consuming entitlements differs between different platforms and stores.