- Home /
How to let the player save progress
Basically, I would like to know how to make it so that a player can save their progress and open a saved game again from a menu. I am new to game design so, hopefully, someone can leave me an answer that is not too complicated. I know there are already a few instances of questions similar to this one, so I apologize for creating a sort of unnecessary thread, but I did not fully understand some of the answers to the other questions like this one. I can do a simple GUI menu, but I have no idea how to actually create and load a save file. Please advise. I am sure many others may benefit from your responses. Thank you!
Answer by _Petroz · Apr 11, 2011 at 05:15 AM
This is known as serialization. There is essentially two parts to this question, how to serialize data, how to do file I/O. When I did serialization for my game I used PlayerPrefs which worked quite well. If you specifically want to write out to file with your own file format specification that is another matter which I don't have any experience with in Unity.
With serialization the first step is to determine what part of the game state is important to save and load, and which state can be easily thrown away.
For example: the player's health, the player's money, the player's position are things you probably want to save. The state of a particle emitter, or the soundsystem are things which you can happily discard.
Once you have determine what to save, now you just have to save them. A common approach is to have every object know how to save itself. So every object which contains state you want to save would have a function called something like 'writeSaveFile' and a matching read, 'readSaveFile'. Inside those functions you perform the serialization, making sure that the save and load function match exactly.
look on the unify community wikki for an xml serialization script, which does what Petroz described above.
Your answer
Follow this Question
Related Questions
Clearing a GUI and Pausing a Game 1 Answer
Game saves/cache lost 0 Answers
How to save user levels? 0 Answers
Save Time Button Settings in Player Prefs 2 Answers
gui Walkie talkie 1 Answer