- Home /
The question is answered, right answer was accepted
Saving Player Data
A can't figure out how to save position, scene, variables and stuff like that to file using binary formater.
I know how to save created class to file, but i don't know how to change position, scene name, variables and stuff into single class and load it again.
Can you give me some good tutorial with saving trough scene and to file (and loading of course)?
I'm using C# and hadn't lot of object oriented programming experience.
I'm struggling with it for almost 5 days :(
You could take a look at Unity Save Load utility to get you started.
Bear in $$anonymous$$d though, saving and loading complex scene data is a very difficult task and it will be neccessary to spend weeks of reading and trial & error until you get some stable and reliable.
Thanks for help, I'll test this utility. And looks like I need more C# experience to make whole projects :D
Not sure if this is even helpfull but i might as well put it out there : You could also use playerPrefs ... This saves your data to a file for you
https://docs.unity3d.com/ScriptReference/PlayerPrefs.Save.html http://answers.unity3d.com/questions/726178/how-do-i-use-playerprefs-to-save-my-score.html
If you want to save data through scenes btw, you might look at "dontDestroyOnLoad" This way you make a gameObject, save stats to here, and just make sure it doesn't get destroyed on loading a new scene.
Answer by game4444 · Aug 29, 2017 at 01:04 PM
Preferably i would say use Json files or xml file to store data. LIke for saving and loading game. But you can use playerPrefs as well. But in this you would required number of playerPrefs to store your data.
The whole data could be stored in one single string, though. It''s how UnitySerializer did it. However, PP doesn't work with extremely long strings so once the amount of data reaches a certain size it will produce errors.
Thank you so much for your reply. I didn't know about this that PP has limit. You are exactly right.
Answer by misher · Aug 29, 2017 at 09:00 AM
U can use json file to store your data. Create serialized class with all necessary structure for your data (use primitive data types only: integers, floats, strings, bools, arrays of primitives etc), then use Json Utilityto create a json string so you can save into a file.
Answer by Wokarol · Aug 29, 2017 at 12:38 PM
If I remember well player pref and json file are readable, so this is bad place for data like position, progress and this stuff.