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

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

Last updated on July 28, 2025

Connect the UI to display player's wallet info

  1. Open the WalletBalanceWidget_Starter CPP file, navigate to the NativeOnActivated() function, and replace the existing implementation with the code below. This updated code binds the ShowBalance() function to the WalletEssentialsSubsystem_Starter's response delegate, which you implemented on the previous page. With this setup, the wallet info will be refreshed each time the WalletBalanceWidget_Starter widget is reactivated.

    void UWalletBalanceWidget_Starter::NativeOnActivated()
    {
    Super::NativeOnActivated();

    WalletSubsystem = GetGameInstance()->GetSubsystem<UWalletEssentialsSubsystem_Starter>();
    ensure(WalletSubsystem);

    WalletSubsystem->OnQueryOrGetWalletInfoCompleteDelegates.AddUObject(this, &ThisClass::ShowBalance);

    // Update balance.
    W_Root->ClearChildren();
    CurrencyBalanceEntryMap.Empty();

    UpdateBalance(ECurrencyType::COIN);
    UpdateBalance(ECurrencyType::GEM);
    }
  2. Navigate to the NativeOnDeactivated() function and replace the existing implementation with the code below. This code clears the binding to the WalletEssentialsSubsystem_Starter's response delegate, ensuring no updates are triggered when the widget is deactivated.

    void UWalletBalanceWidget_Starter::NativeOnDeactivated()
    {
    Super::NativeOnDeactivated();

    WalletSubsystem->OnQueryOrGetWalletInfoCompleteDelegates.RemoveAll(this);
    }
  3. Navigate to the UpdateBalance() function and replace the existing implementation with the code below. This code calls the QueryOrGetWalletInfoByCurrencyCode() function from the WalletEssentialsSubsystem_Starter, which you implemented on the previous page.

    void UWalletBalanceWidget_Starter::UpdateBalance(const ECurrencyType CurrencyType)
    {
    const FString CurrencyCode = FPreConfigCurrency::GetCodeFromType(CurrencyType);

    UWalletBalanceWidgetEntry* Entry = CreateWidget<UWalletBalanceWidgetEntry>(this, CurrencyBalanceClass);
    ensure(Entry);

    Entry->Setup(FText::FromString("..."), CurrencyType);
    W_Root->AddChild(Entry);
    CurrencyBalanceEntryMap.Add(CurrencyCode, Entry);

    // Always retrieve from backend to make sure data is updated.
    WalletSubsystem->QueryOrGetWalletInfoByCurrencyCode(GetOwningPlayer(), CurrencyCode, true);
    }

Resources