Saving/Loading custom data for game, where to put functionality?

Hello everyone,

I’m making a very simple 2D game but I need file saving/loading to disk. I know how to do the file saving/loading, but my question is where to put it? My initial thought was the GameState class, as I clearly remember that there was an Init() function or something like that, that is ran when the game is started. But I cannot seem to find the correct method.

1.Can somebody point me on this?

Also in the documention, I quote

I’m trying to keep track of 2 player properties, the player name, color that he chose and 2 game properties game length between rounds, and the total rounds to play. Give what was said in the documentation, it seems keeping player data is not really a good place. For the player, the player state would be a good place. But I don’t want to have code copy/paste code on two different classes.

  1. Could there be a mechanism, that can read an entire config file (mine is json) that reads the data in a higher level object, and then passes it to PlayerState (for name and color) and GameState (for rounds and timer)?

So I usually use the Game Instance, and the Init() function in that class. This is mainly due to this being called first, before other classes. You could use the BeginPlay of the gamestate, and load the save there and store it on your game state. It just means that if you perform a map load, the game state can sometimes be destroyed a re-spawned in the new map, meaning it would have to load again, where-as the Game Instance is persistent from the start.

Oh I feel so bad now. Of course it’s the Game Instance… Just found some wiki’s on this, thanks for the help.