Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Serialization Confusion

Discussion in 'Documentation' started by sjml, Oct 12, 2017.

  1. sjml

    sjml

    Joined:
    Feb 17, 2017
    Posts:
    1
    Hey folks!

    I had a whole lot of confusion this week over Serialization -- I was following the examples of how to save/load data in Unity, which point to BinaryFormatter as the way to go. (Specifically this video, but lots of resources around the net give the same technique.)

    Where I ran into trouble is where I wanted to do some custom serialization/deserialization stuff, and found my way to ISerializationCallbackReceiver. What took me a while to figure out was that this only applied to serialization being done by Unity, where BinaryFormatter is part of the System namespace. I was wondering if maybe it was because I was running the serialization on a separate thread, if the [Serializable] attributes were applied correctly, etc. Went down a lot of rabbit holes before I finally realized that BinaryFormatter doesn't go through the Unity serialization pipeline.

    Now that I understand it, it's obvious, of course, but it may be worth adding a note on the ISerializationCallbackReceiver documentation that it won't kick in when calling Serialize or Deserialize with BinaryFormatter.

    That's all! Thanks for the great work.
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    2,494
    Note that there's nothing preventing you from using ISerializationCallbackReceiver with custom serialization formats. You just have to call the methods yourself.