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 mwozniak93 · Sep 04, 2016 at 03:38 PM · serializationsavebinaryformatter

Serialize Data - After Update

Hello, I have a question about saving data for player. Let's say that some user play my game and after some progress he saves his game progress ( for example saves the list of objects ot type MyClass). After some time I release update in which I extended MyClass with new property. I tested it and BinarySaver freaks out and I get errors. How can I extend this kind of class so BinarySaver doesn't throw errors?

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 Cherno · Sep 04, 2016 at 04:32 PM 0
Share

You have to implement Data Contract Versioning.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Nerull22 · Sep 04, 2016 at 05:28 PM

In the reply to the original post, I would agree that @Cherno response is not wrong. You can implement data contracting to prevent yourself from making changes that break. It's not a bad method. Although I'm guessing that you are already past the point of a preventative measure and instead need something to fix a breaking change.

What I would recommend is providing a version identifier in your serialized data as a first step. If it doesn't have a version number associated, then you can default it to being the first iteration. So what I mean is in whatever you're serializing down, just put in at the beginning or somewhere a variable that says a version number or identifier.

 public const int VersionNumber = 2;

This isn't fantastic, but is an example of what you might do. This isn't great because you would then need to update this number everytime that you make a change.

So now that you have an identifier, you can create an adapter. If you don't know the Adapter Design pattern, I highly recomment this video:

https://www.youtube.com/watch?v=qG286LQM6BU

So you can create an adapter from your previous, into your new data structure. You will need an instance of both serialized data structures in your project so that it can serialize or deserialize the information back and forth, but it's more or less a save file upgrade system.

So the flow of this would be, you go to load a save file. You check its version. And if its version is less than the one that you want, you find an adapter for upgrading from your current to your new system.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

What is the best/easiest way to save a game (or scene) at runtime? 1 Answer

Which types are actually serializable? Is the documentation incorrect or am I? 3 Answers

Save multiple scriptableObjects in just one binary file 2 Answers

Serialization of Animator state 1 Answer

Save System Problems 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