4. Replace the wallet with Safe and compare the work required
Build this example in your Unreal project and compare the result at each step.
On this page
Keep the Normal exercise. Duplicate BP_MiCartera as BP_MiCarteraSafe and the widget as WBP_MiCarteraSafe. Make changes in the copies.
- In BP_MiCarteraSafe, add a Scientific Number Safe Value Component named WalletSafe. During BeginPlay, connect Make Scientific Number (Base 1000, Exponent 0) directly to New Value on Try Set Value, with WalletSafe as Target. Connect BeginPlay execution directly to Try Set Value and check Return Value with Branch; on False, connect Out Error to Print Scientific Number Error. Do not add Try Make Safe Scientific Number: New Value takes an ordinary Scientific Number and the component protects it internally. If you already added that intermediate node, remove it and reconnect both wires directly. The component is already initialized to zero before BeginPlay; here you set its initial balance to 1000.
- In WBP_MiCarteraSafe, change the Cartera variable type to BP_MiCarteraSafe Object Reference. Compile. In the Actor, change Create Widget to WBP_MiCarteraSafe and reconnect Self.
- In ActualizarSaldo, replace Normal’s Get Value with Try Get Value from WalletSafe. Add Branch. On True, format Out Value and update TXT_Saldo. On False, show Could not authenticate balance; do not replace it with zero.
- In Produce, use Try Add on WalletSafe, Amount 25. Check success/error and refresh the authenticated read.
- In Buy, use Try Spend on WalletSafe, Cost 100. This node returns whether it could spend and preserves the balance if it cannot. On False, distinguish Out Error = None (insufficient balance) from a numeric/authentication error. Do not reinitialize WalletSafe or recreate 1000 on every click.
- In the level, replace the Normal instance with the Safe one. Repeat the full table above and pause on Try Spend to inspect the pins.
- To trigger a numeric failure, temporarily add a third button that runs Try Divide with Amount zero. It should return False/DivisionByZero, and a later read should retain the previous balance.