- Home /
C# how to save values to a File and Load Values from a File
Hi Everyone,I have a question on my mind. Say Like I have 3 integers how would I go about saving them to a file and loading them from a file? If possible could you please explain how it all works through comments? I have seen examples of how it is done but still I don't understand how it all works.
Answer by coastwise · Dec 12, 2012 at 09:48 PM
I would say the preferred way to do this would be to use PlayerPrefs rather than an actual text file.
But playerprefs is limited to floats, ints, and strings, what if I needed to save something else that playerprefs didn't cover?
Then you use or develop a form of serialization for the data you need to store. Exactly what this will entail depends on the size and type of data. In essence though, a string is just a set of data, and any piece of data in the world can be represented/stored as a string.
Your question was asking about storing three integers. Those are covered by PlayerPrefs. Whatever you were going to put in an arbitrary "file" is going to need to be converted to a string anyhow (textfile) or by$$anonymous$$rray (binary file). Either way you're going to need to look into Serialization mechanisms.
Answer by Nidre · Dec 13, 2012 at 05:29 PM
Well you can still use Playerprefs for saving any value.Arrays objects etc.You just have to encode your data and save it as stinrg.Then when you want to load it back you can decode it and assign to your variables.
But if you are looking for a complete solution that works,free,easy and quite good you can give a try to http://whydoidoit.com/unityserializer/