Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Junwenlo · Oct 31, 2015 at 12:43 PM · mobileserializationdatastoragepersistent

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!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by beppim · Oct 31, 2015 at 02:08 PM

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 :) 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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Oct 31, 2015 at 02:35 PM 0
Share

Player can also alter binary file as long as you do not encrypt the content. It's just that xml/json are simple text file but a simple binary parser will give a text file of your binary content.

If you need a json parser : https://unitygem.wordpress.com/json-serializer/

avatar image beppim fafase · Oct 31, 2015 at 03:03 PM 1
Share

Of course that is true, but the number of users that are able to parse a binary file, or even know where to find the file, is just a tiny fraction. If the game is not online it's not so urgent to avoid such cheatings.

avatar image Junwenlo · Oct 31, 2015 at 04:50 PM 1
Share

Thanks for your insight! The binary serialization issue is there since Unity 3.5x though and this turned a number of people away from using it for iOS. But I guess the work-around codes I found should be able to solve it, and your confirmation on the android side is of a great help to me. I'm using binary serialization! Thanks, have a nice day!

avatar image beppim Junwenlo · Nov 02, 2015 at 01:42 PM 0
Share

That's help to me too, as soon as I didn't know about these issues, I'll check whenever I'll need to export to IOS, thank you :)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Data Storage 5 Answers

Serializing Dictionary with Vector3 keys 1 Answer

how to serialize unity variables? (Sprite, Image ...) 1 Answer

How would I store player data? 3 Answers

What is this data that keeps saving when i load my game? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges