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
1
Question by andycodes · Jan 11, 2018 at 03:03 PM · serializationsave databinaryformatter

is it bad practice to have multiple serialized binary files for one save game?

I just watched the persisting data tutorial session (link) and learned about using serialization with singleton design. In the tutorial, all the save data (though minimal) was saved to a single file. In a real-world development scenario, would a want to always save all data to a single save file, or would it be just as well to split data into multiple files to keep things organized (and potentially minimize data loss in the case of corruption).

For example:

Consider the private classes playerData , LastSession, and GeneralSettings (which i know this last class is better served going into player prefs, but for the sake of example lets say it gets saved to a binary file). Following the tutorial, I would naturally try to save all this data into a file "AllData.dat" (Though hopefully a more creative name), and parse the data into all its individual data on load.

However, would it be just as acceptable to store a "PlayerData.dat", "LastSession.dat" and "GeneralSettings.dat" to separate them according to the relevant data inside? One downside I potentially see to this would be that it would make it easier for a hacker to find and edit relevant data, but if they can deserialize a binary file, they were probably going to figure it out anyway, in which cryptography would be the next step but thats overkill for my purposes.

Alternatively, is it also possible to take the three separate files and wrap them into one "AllData.dat" file?

Comment
Add comment · Show 1
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 PizzaPie · Jan 11, 2018 at 04:26 PM 1
Share

I would keep settings seperate from saves probably in seperate directory too, as they have nothing to do with each other and handled differently, as for the saves keep a single file with anything that is needed to perform a load, breaking it to more files doesn't help if either one is corrupted, as all are needed to load.

Furthermore don't bother to make this data harder to be peeked at especially on developing process (text format/xml/json and so on are easy to be read manually for debug reasons of course) and if it is a single player game if someone wants to read/change those save data, just let them, it breaks their experience of the game.

Using a class that encaplulate other classes, as proposed below, is a must for organizasion but try to save the bare $$anonymous$$imum (for example for an inventory i like to save only the ids/ammounts, each item has an id, and any other value that can be changed, highly depends on the game).

Lastly try to avoid playerPrefs it is not nice to bloat the registry and deleting the game won't delete those entries unless an unistall wizard is used to take care of that, always hated games that leave chunks and bits all over the disc.

Cheers.

1 Reply

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

Answer by Bunny83 · Jan 11, 2018 at 03:47 PM

Why don't you create another "SaveData" class that holds your three class instances and you just serialize the SaveData class? The BinaryFormatter can serialize complex object trees.


Though the BinaryFormatter is not the best choice for savegames. Your existing savegames will break when you change anything in your serialized class. This includes adding, removing or renaming of fields.


If you like binary serialization just manually using a BinaryWriter / BinaryReader to write your desired values directly to the file. Of course it's recommended to store a version number in case you change something in the future.


Though formats like XML or JSON are much more flexible.

Comment
Add comment · Show 1 · 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 andycodes · Jan 11, 2018 at 06:22 PM 0
Share

Thanks for the information! I'll likely look into X$$anonymous$$L or JSON for the data persistence structure in this case to ensure the structure is future proof.

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

79 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Save multiple scriptableObjects in just one binary file 2 Answers

Google Cloud Save Data returns empty. 1 Answer

BinaryFormatter - saving and loading a list containing sprites. 0 Answers

Why am I getting SerializationException: Type 'UnityEngine.MonoBehaviour' etc. 1 Answer

Binary serialization layout on different platforms 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