Protect a balance with Safe values
Authenticate reads, reject an unaffordable spend and preserve the previous value.
On this page
Create and retain the value
- In your Actor Blueprint, add a variable
SafeBalanceof type Safe Scientific Number. - From BeginPlay, execute Try Make Safe Number with In Value set to Make Number 1000.
- Branch on Return Value. On True, assign Out Safe Value to SafeBalance. Handle False without creating a replacement balance.
- Execute Try Get Safe Number using SafeBalance. Only use Out Value when its success output is True.
Spend from the same variable
Connect a Get of SafeBalance to the by-reference Value input of Try Spend Safe. Use a cost of 250. After success, read the same variable again.
The spend succeeds and the authenticated balance is 750. A subsequent spend of 1000 returns False with OutError=None and leaves 750: insufficient funds is a business outcome, not a numeric authentication failure.
Do not call Try Make Safe Number with 1000 before every spend. That recreates the starting balance instead of updating the retained wallet. Invalidating the Safe value should make subsequent authenticated reads fail.
Bind a value to its context
Use a Context Bound Safe Scientific Number variable. Set its value with a stable Context Domain GUID and Context Name such as Coins. Read with the same pair. Changing only the name to Gems must reject the read. Rekey with the correct context preserves the numeric value.
Know the boundary
Safe values authenticate in-memory storage; they do not supply account authentication, server authority or an anti-cheat service. Raw Safe memory and AI handles are not portable saves. Use a save session for recovery across processes, and components when an Actor should own the value and emit notifications.