Search Unity

Json Not serializing private fields marked with SerializeField

Discussion in 'Scripting' started by Chris-Trueman, Sep 24, 2017.

  1. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    I'm trying to get some fields to save to Json. If I leave the fields public they save no problem. If I mark them with SerializeField and have them private, they do not save. Is this a bug or intended?
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,609
    According to the documentation, it must be a bug.
    https://docs.unity3d.com/Manual/JSONSerialization.html

    If the same rules apply as they do in the Inspector, I'd expect it to serialize private fields via SerializeFieldAttribute.
     
  3. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    Hmm created a test project to see if it worked, and it does. Maybe something isn't setup right in my other project.
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,261
    I feel quite stupid right now. Was trying to find out what was going on and I found that I'm not even using Json to save my information. Turns out I was using XML, switched over to Json and everything is working fine.
     
    Peter77 likes this.