Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to save data in Unity game [closed]

I was wondering... What's the best way to save data in Unity games. JSONs? If so, how? Thanks

like image 487
messedupsongguy Avatar asked Dec 23 '15 00:12

messedupsongguy


People also ask

Where do Unity Games save game data?

Where Are the Unity Save Files Located? While there is no universal save file location, the unofficial locations for Unity save games are all located by default in 'persistantDataPath,' in the application. If you are only using Unity PlayerPrefs, then the data will simply be in the registry.

Does Unity save on play?

It's often most convenient to adjust camera settings while the game is playing. But normally, Unity does not save your changes to the Scene when you exit Play Mode.


2 Answers

Here are some of the different Ways and Methods to Save data for Unity Projects:

  1. Platform-Independent: One way of saving data in Unity3D in a Platform-independent way is to use the PlayerPrefs class. (Learn More 1, 2). PlayerPrefs is a static class and it is very easy to use but not reliable.

  2. PERSISTENCE - SAVING AND LOADING DATA using DontDestroyOnLoad, PlayerPrefs, and data serialization Video Tutorial by unity.

  3. Server Side: You can also use a Server for saving data (like a combination of PHP and MySQL Database). You can use it to save Score Data, user profile, etc., Learn More From Unity Wiki

  4. For saving the in-game data to a Hard drive in a format that can be understood and loaded later on, use a .NET/Mono feature known as Serialization. Learn More

  5. Simple JSON guide about Unity is available at Unity Wiki or officially you can see JSON serialization

  6. SQLite (an embedded database for your app) is another great option for you to get the Free Package, it is simple and easy (and my favorite) if you know SQL.

  7. Scriptable Object: its a data container. Useful for unchanging data. Suitable for large unchaning data and aamazing safe projects memory.

enter image description here

The above is taken from my blog post on Data Saving Techniques for Unity3d Applications.

like image 184
Muhammad Faizan Khan Avatar answered Sep 24 '22 13:09

Muhammad Faizan Khan


You can use many assets that are available for free and paid in asset store.

Save Game Free - XML and JSON saving and loading.

Syntax:

Saver.Save<T> (T data, string fileName);

Example:

Saver.Save<MyData> (myData, "myData"); // The .json extension will be added automatically

Save Game Pro - Binary saving and loading. fast and secure. Easy to use.

Syntax:

SaveGame.Save<T> (T data, string identifier);

Example:

SaveGame.Save<int> (score, "score");
like image 38
Empire Avatar answered Sep 23 '22 13:09

Empire