- Home /
The best way to save and load data for mobile in unity ?
Hi,
I just wanted to know what is the best way to save data for mobile games in unity for both platforms Android and iOS. For the moment i only know PlayerPrefs class but this wasn't secure asi understood. I am finishing my first game for mobile and wanted to know how to save data like score and unlocked items, etc., in users mobile phone and Google Play Services too. Also, how can I save data online like Google Play Services for iOS platform too ?
I'd be grateful if you suggested me something because I have no idea how to achieve this for the moment. Share links and sites too if there is any tutorial for any of these methods in saving mobile game data.
Thank you, Gerald Bathorja.
There is no best way. Some games safe a few things others way more... It also depends on the type of data. Volume? Hacking wouldn't really hurt here, right?
There are several ways of writing binary data, readable (X$$anonymous$$L, JSON) and unreadable (custom).
You can always run those through some encryption algorithms too
Thank's for your reply. $$anonymous$$ost of data type are integers and string. I was interested saving these data on google play services too. Does the same thing apply for iOS platform too ? Or should I use Game Data Center for iOS devices ?
Answer by fermea_t · Jun 20, 2017 at 08:48 AM
Hello,
I'm not an expert but I advice you to check about the ScriptableObject. That is easy to store data.
You can find some tutorials about it here : https://unity3d.com/fr/learn/live-training Here is an introduction to Scriptable Objects : https://unity3d.com/fr/learn/tutorials/modules/beginner/live-training-archive/scriptable-objects
However I hope for you that someone who know more about the subject will respond to you.
Have a nice day.
Timothée Fermeaux
Thank's for your suggestion. I am not sure if scriptable object is what I need but I will check it anyway.
What do you need to store ? GameObjects, Attributes ?
Because for the score I think you are using an int and for the Unlocked Items a List.
Then you can create a ScriptableObject named GameInfo and put a private unsigned int m_BestScore attribute that store the best score of the player with a public method GetBestScore() to get the attribute and a public method CompareBestScore(unsigned int score) to compare the value of the current score with the best one and if the new score is better then you change the value of m_BestScore. I don't know how you will store the "Unlocked Items", but you can declare again a private List m_UnlockedItems attribute which store all the unlocked items with T is the type of one Unlocked Item that can be an enum or a GameObject, I don't know exactly ^^. Then you can add a public method IsUnlocked(T item) which returns a boolean if the item is unlocked, and you can add a public method to add an item to the list.
When you change an attribute you can Save() and then you have all your data saved.
ScriptableObjects are made to store data and it's easy and it's specifically made for Unity.
It has better performance than Json, X$$anonymous$$L ...
Great thank you, what about saving player score and unlocked items to Google Play Services ? Is it the same with iOS ?
Thank's again for the info. ;)
Your answer
Follow this Question
Related Questions
Load Xml on Android with XmlReader 2 Answers
Issue saving data accross multiple platforms 0 Answers
Saving data files in iOS 3 Answers
PlayerPrefs for unlocking items 1 Answer
Load from Xml on Iphone and Android 2 Answers