NO MOM
I CANT PAUSE.
Scientific Number Tools Documentation
Support
Browse lessons

3. Build a real wallet with an interface you can click

Build this example in your Unreal project and compare the result at each step.

On this page

You will create a UMG interface with buttons to produce resources and buy items. Each operation updates the balance and shows whether the purchase succeeded.

Prepare the owning Actor

  1. In Blueprints, create another Actor named BP_MiCartera. Open it.
  2. In Components, click Add and search for Scientific Number Value Component. Name the component Wallet. Drag it into the Event Graph as Get.
  3. From its reference, add Try Set Value; make sure Target is connected to Wallet.
  4. Add Make Scientific Number with Base 1000, Exponent 0 and connect it to New Value. Connect BeginPlay to Try Set Value. Add Branch using its Return Value. Expected result: True and Out Error = No Error. The value 1000 × 10^0 normalizes to Base 1, Exponent 3; normalization is not an error.
  5. The False branch handles a possible failure; it is not the expected result for 1000. Connect False to Print Scientific Number Error, Out Error to Error, and Context = Inicializar Wallet. Continue to the interface on True. Do not continue through False with a balance that was not initialized.

Create the buttons and text

  1. In the UI folder, right-click → User Interface → Widget Blueprint. Choose User Widget and name it WBP_MiCartera.
  2. Open it in Designer. Add a Canvas Panel if there is no root. Add a Vertical Box inside it, center it with the anchor preset, and enable Size to Content if you need to adjust its size.
  3. Inside Vertical Box, add a Text Block named TXT_Saldo. Enable Is Variable. Give it a readable size, for example 28.
  4. Add another Text Block, TXT_Estado, and enable Is Variable. This will display a rejected purchase.
  5. Add two Button widgets named BTN_Producir and BTN_Comprar. Put a Text Block inside each with Producir +25 and Comprar −100, respectively.
  6. In Graph, create a variable Cartera of type BP_MiCartera → Object Reference. Enable Instance Editable and Expose on Spawn. Compile the widget.

Show the widget

  1. Return to BP_MiCartera. From the True branch of initialization, add Create Widget, Class WBP_MiCartera.
  2. Connect Get Player Controller to Owning Player. Connect Self to the Cartera pin on Create Widget.
  3. If Cartera does not appear, check Expose on Spawn, compile the widget, and use Refresh Node or create Create Widget again.
  4. Connect Create Widget’s Return Value to Add to Viewport.
  5. Use Set Input Mode Game and UI, connect Get Player Controller to the Player Controller pin and the created widget to In Widget to Focus. In the Player Controller, set Show Mouse Cursor = true.
  6. Do not add a second Set Value at the end: the wallet must keep its balance across clicks.

Read the balance in the interface

  1. Open WBP_MiCartera, Graph tab. Create a function named ActualizarSaldo.
  2. Drag Cartera as Get. From it, get Wallet. From Wallet, add Get Value.
  3. Connect the value to To Fixed String, Decimal Places 2. Connect the text to Set Text (Text) whose Target is TXT_Saldo. Unreal may insert the String → Text conversion.
  4. Connect the function’s white execution input to To Fixed String, then to Set Text. Compile.
  5. In EventGraph, connect Event Construct → ActualizarSaldo. The Cartera reference is already supplied when the widget is created.

Program the buttons

  1. In Designer, select BTN_Producir. In Details → Events, click + OnClicked. Unreal opens its event in Graph.
  2. From Cartera → Wallet, call Try Add, Amount = Make Scientific Number 25. Connect OnClicked to the node, then to Branch using Return Value.
  3. On True, clear TXT_Estado with an empty Set Text and call ActualizarSaldo. On False, show a failure message and inspect Out Error. Do not simulate the balance by changing only the text.
  4. Create OnClicked for BTN_Comprar. Get Wallet from Cartera and call Get Value; connect the result to Can Afford, Resources Available. Price = Make Scientific Number 100.
  5. Connect OnClicked to Branch using the Can Afford result. On False, connect Print Scientific Number Error: Out Error → Error, Context = Comprar, and No Error Message = Saldo insuficiente. With balance 25 and price 100, Can Afford returns False / No Error and Print displays Comprar: Saldo insuficiente. A real error takes precedence over No Error Message. Keep this Print on the False branch: if it also runs on success, it will print the fallback text too. For a widget message, also update TXT_Estado; Print is for development only. Can Afford compares balance and price; it does not perform or simulate the subtraction.
  6. Get Cartera → Wallet and drag from its blue object pin to search for Try Subtract. This is a method of Scientific Number Value Component (Normal): when searching from the Branch’s white execution wire, the context menu may not show it. Connect Wallet to Target, True → Try Subtract execution, and Make Scientific Number 100 to Amount. Check Return Value with another Branch; only on success clear the status and call ActualizarSaldo. Do not replace this with Try Add using -100 while Idle is active: the negative number is rejected when constructed; Try Subtract takes the positive price.
  7. Compile both assets and save. In the level, remove only the BP_MiNumero instance you placed, or disable its test; do not delete the asset. Place one instance of BP_MiCartera.
  8. Run and click inside the game. You should see two buttons and an initial balance of 1000.00.

Use your wallet

What you do What should happen
Click Produce once 1025.00
Then click Buy once 925.00
Stop Play and run again 1000.00: this wallet does not save a game yet
Buy ten times starting from 1000 0.00
Buy one more time Still 0.00 and Insufficient balance appears
Produce four times and buy Returns to 0.00 and the previous message disappears
Add a breakpoint to Try Subtract You see the button call and the component that changes

To adapt the interface to your game, keep the purchase button active and explain rejections in TXT_Estado, or disable it when the balance is insufficient. Check the balance when executing a purchase even if the button already reflects availability.