Keep variables running (like income) while game is closed
Genuinely think this is the last piece of coding ill need to learn for my project (hoping)
The player has a source of income (variable called income) that is constantly being added to his total money (total). It is an incremental game so i would like for the income to continue adding to the players total even when they have closed the game. This is added every second by just using the Delay node.
Ive heard of the "Get accurate real time" node but Ive no idea how to use it
So, question is, how would i keep the variables running even when the game is closed?
Example, the player has 100 money, and the income is 1 per second. If the player closed the game for 60 seconds, they would have 160 money when they open it again
asked Mar 20 '17 at 08:25 PM in Blueprint Scripting
Something like this using GameInstance should work.
It will require creating a game instance class, and setting it as the default in project settings. Then add the following nodes:
EventShutdown, and EventInit are not custom events, right click and type their names to find them. CurrentTime and LastCloseTime are DateTime type.
You will also need to create a save game class, do that and add a DateTime variable in it, CloseTime. In the create save game object, put you custom save class.
You'll just need to account for things like when it is first run and their is no save, and also, if the game crashes or closes unexpectedly I doubt EvenShutdown will be called. So you could have it periodically update the LastClosed time, even when the game is still open, by overwriting that save.
answered Mar 20 '17 at 08:56 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here