Stuck on saving Character Data.

Hello Unity,

I have hit a roadblock and I think I am probably overthinking this. But I cant figure out how to get past it.

I want to save some very basic information about characters in my game. Upon booting the game up, you arrive at a character selection screen. You can also create a character. I am looking for the best way to allow players to save several different characters with different names and characteristics. I dont need to save scenes or progress in a level, or actual gameObjects or anything like that.

Basically I just have a custom class called PlayerDataClass that saves my Character’s name, XP, Level, etc. Just some basic characteristics.

My thought is I would give each player an array of playerDataClass’s - each segment of the array containing all the characteristics: level, xp, etc.

I have looked at playerPrefs, JSON, XML. I am just not sure of the right way to go. These all seem to do way more then I need. I just want to save some basic strings and ints but I need them to all be listed under one character, hence the custom class PlayerDataClass.

What would be the best way to go about this? Is having all the character data under one class a good idea?

I know this is more of a C# question than a unity question but this is the most helpful forum around! :slight_smile: Thanks very much folks.

You could create parallel arrays from the PlayerDataClass data and save them with ArrayPrefs2, then load them the same way and reconstruct the PlayerDataClass array. Or, preferably, extend ArrayPrefs2 to save the PlayerDataClass array directly.

Well this is all fine, but i guess you are trying to save your data after you finnish playing/making you carater/… and then load it next time.

You can add a function to your PlayerDataClass that forms all relavant data into meaningful form. Might it be XML, pure text or JSON doesent matter. Then you will have to save it into a file.

When you load, process is reversed. If this is PC project you can even check out some JSON parser libraries. They can do serializing and deserializing for you automatically. Then all you need to do is writting and reading a file.

Take this with a grain of salt. I’ve never done this before.

I ended up using binary to store my data - if anyone reading this is interested in how to do this, there is a great post to read about it here: