The save system that was created is quite rudimentary but it does the job. Before making the save/ load system I had to figure out how exactly to do it. From my previous experience I imagined it being done through the use of files and sure enough after a bit of research I found a simple way to save data into a file and load the data from the file.
The process was simple enough, all I needed to do is create a static class with variables I wanted to save and make sure that the object the save/load script is attached to is persistent through different levels, which I did by running “DontDestroyOnLoad” function in the “Awake part of the script. This makes it so the object is not destroyed when an object is loaded.
Save system is quite simple, due to level based nature of the game. Since There are no collectibles right now, the only thing that will differ between saves is the level player is on. Since level the player is on can be represented by a single number, that’s the only thing I save. Originally I was going to save two variables like level and save slot number, but since save slot doesn’t change during the game, I decided not to save unnecessary data, instead I have split each of the save slots into it’s own file. This way a file can correspond to a save slot and I only need to save a level number for that slot. Having a separate file for each slot also allows me to easily expand save system in future by simply adding variables. This wouldn’t be possible before, since each variable would have to be linked to a save slot in some manner so I would have to think about how to make it so that variables with the same names are differentiated in a single file. It’s not impossible, since I could separate file into sections representing save slots or adding a prefix to each variable when it is written into a file. However I decided that having separate files is a better solution.
In the end what I ended up with is a system that consists of 3 save slots each dedicated to a separate file. If there is no file. game can’t be loaded from that save slot and instead a “No save data found” is displayed.
0 comments