A simple way to set up saving and loading in your game is to use a SaveGame object.
Think of the SaveGame object as a box with different compartments. You set up each compartment to store a particular piece of information by creating variables. For example, you could
create a variable to save the player's score, as well as the player's name. You can transfer information into the SaveGame object from other classes, like your Character, PlayerController, or GameMode.
To do this, first you must create an instance, or copy, of your SaveGame object.
Then, for example, you can take the values for the player's score and name from the PlayerController, and store them in the matching variables in the SaveGame object.
The SaveGame object will now hold on to these variable values until it is saved to the hard drive.
Finally, you can save out the SaveGame object to a file on your hard drive by using SaveGameToSlot. This works just like saving a document or a new game in other programs, since you
give SaveGameToSlot a file name. By default, save games are stored as
.sav files in the
You also must give SaveGameToSlot a user ID, which will help in looking up the information to load later on.
Loading information from a SaveGame object is also a simple process, which is almost the reverse of saving information. You use the LoadGameFromSlot function, which takes in the file name
and the user ID as input. Loading information from the hard drive with LoadGameFromSlot creates a new copy of the SaveGame object.
You can use this object to copy information into other objects and Actors in your game. In this example, we are loading the player's score and name into the PlayerController, much like you would
when a player opens up a saved game and begins playing again.