メインコンテンツまでスキップ

Put it all together - Entitlements Essentials - (Unreal Engine module)

Last updated on December 17, 2025

Connect the UI to the entitlements

  1. Open the OwnedCountWidgetEntry_Starter CPP file, find the RetrieveEntitlementWithForceRequest() function, and replace the existing implementation with the code below. This updated code calls the GetOrQueryUserItemEntitlement() function you implemented earlier and binds ShowOwnedCount() as the on-complete delegate.

    void UOwnedCountWidgetEntry_Starter::RetrieveEntitlementWithForceRequest(const bool bForceRequest)
    {
    SetVisibility(ESlateVisibility::Collapsed);

    const ULocalPlayer* LocalPlayer = GetOwningPlayer()->GetLocalPlayer();
    W_Parent = GetFirstOccurenceOuter<UStoreItemListEntry>();
    if (W_Parent && LocalPlayer)
    {
    // Get item.
    const UStoreItemDataObject* ItemData = W_Parent->GetItemData();
    if (!ItemData)
    {
    return;
    }

    EntitlementsSubsystem->GetOrQueryUserItemEntitlement(
    LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId(),
    ItemData->GetStoreItemId(),
    FOnGetOrQueryUserItemEntitlementComplete::CreateUObject(this, &ThisClass::ShowOwnedCount),
    bForceRequest);
    }
    }
  2. Open the EquipmentInventoryWidget_Starter CPP file and replace QueryEquipmentItems() and SaveEquipments() so they actually query and save the player’s equipment, respectively.

    void UEquipmentInventoryWidget_Starter::QueryEquipmentItems()
    {
    const ULocalPlayer* LocalPlayer = GetOwningPlayer()->GetLocalPlayer();
    if (!LocalPlayer)
    {
    UE_LOG_ENTITLEMENTS_ESSENTIALS(Warning, "Failed to save customization. Local player is invalid.");
    Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Error);
    return;
    }

    const int32 LocalUserNum = LocalPlayer->GetControllerId();
    const FUniqueNetIdPtr UserId = LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId();
    Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Loading);

    // Get the equipment items.
    EntitlementsSubsystem->GetUserEquipments(
    LocalUserNum,
    UserId,
    FOnUpdateUserEquipmentsComplete::CreateWeakLambda(this, [this, UserId]
    (const FOnlineError& Error, const FPlayerEquipments& Equipments)
    {
    // Store current equipments if any.
    if (Error.bSucceeded)
    {
    CachedEquipments = Equipments;
    }

    // Query entitlements to be displayed.
    EntitlementsSubsystem->GetOrQueryUserEntitlements(
    UserId,
    FOnGetOrQueryUserEntitlementsComplete::CreateWeakLambda(this, [this]
    (const FOnlineError& Error, const TArray<UStoreItemDataObject*> Entitlements)
    {
    if (!Error.bSucceeded)
    {
    Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Error);
    return;
    }

    CachedEntitlements.Empty();
    CachedEntitlements.Append(Entitlements);

    W_Inventory->RefreshCategories();
    W_Inventory->SwitchCategory();

    Ws_Root->SetWidgetState(EAccelByteWarsWidgetSwitcherState::Not_Empty);
    }));
    }));
    }
    void UEquipmentInventoryWidget_Starter::SaveEquipments()
    {
    const ULocalPlayer* LocalPlayer = GetOwningPlayer()->GetLocalPlayer();
    if (!LocalPlayer)
    {
    UE_LOG_ENTITLEMENTS_ESSENTIALS(Warning, "Failed to save customization. Local player is invalid.");
    return;
    }

    const int32 LocalUserNum = LocalPlayer->GetControllerId();

    UAccelByteWarsGameInstance* GameInstance = Cast<UAccelByteWarsGameInstance>(GetGameInstance());
    if (!GameInstance)
    {
    UE_LOG_ENTITLEMENTS_ESSENTIALS(Warning, "Failed to save customization. Game instance is invalid.");
    return;
    }

    UPromptSubsystem* PromptSubsystem = GameInstance->GetSubsystem<UPromptSubsystem>();
    if (!PromptSubsystem)
    {
    UE_LOG_ENTITLEMENTS_ESSENTIALS(Warning, "Failed to save customization. Prompt subsystem is invalid.");
    return;
    }

    PromptSubsystem->ShowLoading(TEXT_SAVING_EQUIPMENTS);
    EntitlementsSubsystem->SetUserEquipments(
    LocalUserNum,
    LocalPlayer->GetPreferredUniqueNetId().GetUniqueNetId(),
    CachedEquipments,
    FOnUpdateUserEquipmentsComplete::CreateWeakLambda(this, [this, PromptSubsystem]
    (const FOnlineError& Error, const FPlayerEquipments& Equipments)
    {
    PromptSubsystem->HideLoading();
    if (!Error.bSucceeded)
    {
    PromptSubsystem->ShowMessagePopUp(ERROR_PROMPT_TEXT, Error.ErrorMessage);
    }
    DeactivateWidget();
    }));
    }

Resources