- Home /
Saving usermade creations in game
I'm making a game where the player is able to make things in game, ranging from a building to weapons and gear they will use. Right now focusing I'm on the Buildings and trying to figure out what would be the best way to save the creations. Should use Xml files, playerperfs or something else. Keep in mind that for the building side of things the player can build a whole town if he or she so wish.
Answer by cordinc · May 04, 2012 at 09:06 AM
The 3 main options are PlayerPrefs or C# serialization or a text format, XML being the most obvious. If you want to be able to read/edit the save files outside of Unity then I would suggest XML, otherwise use C# serialization.
PlayerPrefs (documentation here) seems to be for storing small amounts of data and only handles ints, floats and strings. You will find it difficult to fit a whole town in this manner! Also, on Windows PlayerPrefs are stored in the registry - not a good idea to store too much there.
C# Serialization will require some coding on your part to get it set up and you will need to decide where to save the resulting files. It produces small save files, but you won't be able to look at them in other tools as they will be in binary format. There are some details on how to do this at the answer to this question. If you don't want users (or yourself) to be able to look and edit the save files, this is probably the best choice.
The other format is XML. It should require about as much coding as C# Serialization, but the save files will be larger. However, you will be able to read them as text. More details on this web page.
About C# serialization can i take the save data out of one game and move to another?
Yes, if the other game has the same C# deserialization code into the same C# classes (that is both games share the same object model).