How to save a variable? Pls Help

Hey guys, I just wanted to program a bank account system. So, I really need to save the money amount of the bank account. But if the player buys something in the Shop website (These are all widgets), the money is debitted from the variable of the shop but not from the bank account, even though I casted it to it, it didnt work. And if I closed the shop website and wanted to buy the things another time, it was the same money amount as before, so the float of my money amount is resetted to default if I go to another widget and go back. It doesnt save the change of the variable and I dont know why. So how can I set a variable for the amount of money from the player and change it from every blueprint and save the amount of money, that it isnt resetted all the time to the default value. Thanks for your help! :slight_smile:

Hi PumaNilpferd85

You can store the “Total Money” variable in the PlayerController. This will remain persistent throughout the level. However, when you change a level, the value of that variable will be reset to default.

You could use the GameInstance, the values will not reset when you change levels. However, I would consider it bad practice to use the GameInstance for data relating to the user.

The best way to go about this is by using a Save object. This will write the variable to your hard disk. It will also allow you to pick up that variable if you restart the application.

Matthew Wadstien did a great tutorial about using save objects: HTF do I? Use the SaveGame Object in Unreal Engine 4 - YouTube

Good luck.

Alex

1 Like