How can i keep a variable's value consistent throughout all the levels?

I have a coin variable for my player, and say i collect 5 coins and then die or exit to the main menu or exit the game, i want the coin value to add everything up so i can spend them in a store for items.

SKYPE: cjsavage56 (red shirt)

EMAIL: cjsavage56@gmail.com

1 …

2 …

3 …seconds to google it and find Saving and Loading Your Game in Unreal Engine | Unreal Engine 5.2 Documentation

Then why did you accept the answer… autist ?

EDIT: Actually since you asked for “exit the game”, my first answer is the good one. If you don’t understand it, I can’t help you.

Are you autistic? That is not what i am asking, i am asking specific.

I know how to save a game.

Check out the GameInstance Blueprint class.

It is a Bp where you can store and change variables that then will carried over from level to level.

It works like a regular Blueprint, but when you set your created Instance as the GameInstance i will then not be reset from level to level, and as such will be where you store your money variable, (and also where you store your bought items when you return to the world).

Won’t work for “or exit the game” though :confused:

Thank you.

No, if you need the variable stored outside of the game, you would than take the GameInstance variable, and place it in a save game object (there are also some good documentation on that if you are unceartian of this).

Then when the game is opened, you load the variable before the main game is started, and place it back into theGameInstance.

With these executions, you will now have the possibility to store your variable between levels/menus and between program starts :slight_smile: