5. Test context with your own variables
Build this example in your Unreal project and compare the result at each step.
On this page
- Create BP_MiContexto, of Actor type. Add a variable SaldoContexto of type Context Bound Safe Scientific Number.
- From BeginPlay, run Set Context-Bound Safe Number on this variable by reference, with In Value 1000 and Context Name Coins. For the GUID, run New Guid once from BeginPlay. Promote its output to a variable named DominioContexto. Connect New Guid output to the value input of Set DominioContexto. Connect execution as BeginPlay → Set DominioContexto → Set Context-Bound Safe Number. New Guid is pure: use it only to assign the variable; use Get DominioContexto for other operations. Connect a Get DominioContexto to the GUID pin. You do not need Make Guid or A/B/C/D fields. Check the returned bool.
- Then call Try Get Context-Bound Safe Number on the same variable, with Get DominioContexto on GUID and Coins on Context Name. Reuse the saved identifier: do not run New Guid again to read. On True, display Out Value through To Fixed String → Print String.
- Place an instance of this Actor and run: expect 1000.00. In the debugger, observe that the read returns True.
- Stop Play and change only the Context Name on the read to Gems. Run: it should return False. Do not also change the writer, or you would no longer be testing an incorrect context.
- Restore Coins. Add Rekey Context-Bound Safe Number between the write and read, using the correct context. The read should still return 1000.