Persistent Data Storage For Mobile Platform

Hi,

I would like to know for my case which would be a single player offline game, are there any other ways other to save game data other than PlayerPrefs, XML Serialization and the built-in Binary Serialization? I would not be touching on the server side as my game wouldn’t require access to the internet.

The data I’m talking about is just like a RPG game where every character has its own dynamic attributes like health, skills, weapons and cooldown time ( just to name a few ) that changes in run time whenever the player upgrades the character. PlayerPrefs is definitely out of the context, as it wouldn’t fit the bill since I’m talking about at least 500 dynamic attributes that has to be saved in the mobile device and stability would be an issue. And since I’m not developing for webplayer, I won’t be using servers to store the data.

For now, it seems that I could only use either the built-in Mono’s Binary Formatter Serialization or the XML Serialization. I’ve heard about Mono’s Binary Serialization having issues with iOS giving JIT Compile Error message as iOS compiles in AOT (Ahead Of Time). Further findings brought me to this that solves the error by attaching another script in the Awake(). My question is, has anyone tried this before? Will it be stable for mobile platform?

XML Serialization is another method in my head now. I’m not particularly familiar with XML, but if the Mono’s Binary Serialization isn’t stable with iOS and other mobile platforms, I would have to look at XML although as far as I know, it doesn’t have the ability to be formatted into binary. This is a quite a trouble as there’s going to be a loophole for players to edit the data. Although binaries won’t completely safeguard the data from being edited, at least it’s a preventive wall for average-Joes to break into.

So, to repeat my question again, are there any other recommended ways for persistent storage in mobile platform other than PlayerPrefs, Binary Serialization and XML Serialization? My game would be targeted for iOS and Android devices.

Thanks!

I didn’t test it on IOS, but on Android I serialize without any problem using the standard way:

		string fileName = Application.persistentDataPath + "/playerInfo.dat";
		BinaryFormatter bf = new BinaryFormatter();
		FileStream file = File.Create(fileName);
		bf.Serialize(file, data);
		file.Close ();

Rather straight forward and doesn’t giv any problem, besides the fact that some types are not serializable. In that case, either you change them using basic data types, or use one of the many serialization extensions that you can find on the assetstore.

If you have performance problems you can as well subdivide the data in more files and read/write only those that you need to.

Another solution would be to serialize data to json and then write it as a text file. This anyway could lead to cheat issues. And by the way this is the only answer to your question, now that I read it a second time :slight_smile: JSON is an alternative to XML as a matter of fact, but as you stated too, players could easily edit it, unless you encrypt it.

Anyway, I would go straight to binary serialization, and if some problems exist on IOS, I’m sure that they are addessed and fixed asap, as soon as such a big problem would be a priority in Unity’s roadmap.