a UMG only game - where to save global var's and how to manipulate them


iam trying to create a tiny buisness simulation only with UMG.

for example : from the main menu u click the button “market” and get to a new widget where u can “buy wood” .
my first question is what is the best way to store all that variables (stockpile for every ressource, cost for every ressource, playermoney etc)?
my second question is: when i press the “buy wood” button in the widget “market” how do i reduce the wood stockpile ressource by one when the variable is not in the widget?
cast to gamemode -> set variable cant be the way this works, can it?

i hope someone can understand what i mean and is able to help me out

UE4 has multiple classes to work with. I assume you build a Singleplayer Game, so lets keep it simple:

The class you want to use is “GameState”. You can create your own one and it can be accessed through “GetGameState” nodes.

Before asking “what’s the difference between GameState and GameMode”, I would love you to check out Epic Games Documentation.
They explain it there: Gameplay Framework Quick Reference | Unreal Engine Documentation

Inside of your own, custom “GameState”, you will want to create variables for your store. So for example a variable “Money”. And/or you create
a struct with “Resource Name” and “stockpile” as variables and create an array of this struct for your store.

And then you can easily, on a button press in UMG, get the GameState and change the variables.
And also get them and display them.

BIGGEST THING TO REMEMBER: Don’t put logic into UMG. Only let the Button presses call functions IN the GameState. Don’t store stuff in a Widget.

Why not store logic in widgets?