Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Weird serialization exception

Discussion in 'Scripting' started by VI_ee, Jul 3, 2017.

  1. VI_ee

    VI_ee

    Joined:
    Nov 14, 2016
    Posts:
    9
    Hello everyone.
    Suddenly I got the issue after hit the play button.
    upload_2017-7-3_11-6-46.png

    the most weird thing is that field enemiesAttractedToAutograph does not exist.

    upload_2017-7-3_11-9-17.png
    I've got tons of other errors from nowhere. I could not find the answer to this, what I've already try to do:
    - delete whole register (regedit)
    -reinstal unity, sourcetree
    -update unity
    -a lot of other things I do not remember right now
    All of my teammates have fully working version of project, errors only appear on my PC, and - yes - I have newest version of the project.
    I would really appreciate all answers, hope You can help me. Thank You :)
     
  2. traderain

    traderain

    Joined:
    Jul 7, 2014
    Posts:
    108
    Without more I can only say that you may be serializing/deserializing the wrong object.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    Yup, that's probably it. It's thrown by SaveLoadManager.LoadFromFile<SavedAchievements>(). Could you post that? You're probably trying to deserialize the wrong thing - either an old version of the type, or something else entirely.

    Edit: You also don't have to cross out bits of your code. We're not going to steal your type and field names, ffs.
     
  4. VI_ee

    VI_ee

    Joined:
    Nov 14, 2016
    Posts:
    9
    @Baste Unfortunately I have to, because of my boss, sorry about that.
    Thank You for your reply, class SavedAchievements just have a bunch of fields, that's all:
    upload_2017-7-3_14-45-1.png


    I also include Load method
    upload_2017-7-3_14-48-19.png

    If I try to deserialize wrong thing, how is it possible, that my teammates does not have this problem? Isn't that weird?

    @Edit
    If I add field "enemiesAttractedToAutograph" error disappear, but new one (exactly the same) appears, with other field, so I add that 'other field' and next one error appears. After adding 10 new fields I gave up, because it is not the solution
     
    Last edited: Jul 3, 2017
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,199
    It seems like the achievement file is broken. Your binary deserializer is finding fields that are not there, and crashes. Going to guess that some other file has been copied to that location. I assume your framework has the ability to delete/reset it somehow? Try that.

    This is the big downside with binary serialization as opposed to string-based serialization. It's faster, sure, but it doesn't handle changing what fields are there very well.
     
    VI_ee likes this.
  6. VI_ee

    VI_ee

    Joined:
    Nov 14, 2016
    Posts:
    9
    Problem solved. Thank You @Baste for Your help, I really appreciate it.
    Solution:
    1. Go to folder where you store your saved files (If You use Application.persistentDataPath, and don't know how to find this, just use Debug.Log(Application.persistentDataPath) to check the path.
    2. Delete your saved files