Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Will JSON be able to serialize private fields?

Discussion in '5.3 Beta' started by AnomalusUndrdog, Oct 7, 2015.

  1. AnomalusUndrdog


    Jul 3, 2009
    I read over the Google doc but I didn't seem to get if it matters whether the field is public or private. What are the rules with this? Is it the same with how it is in Unity right now? (i.e. private fields are not serialized, unless you use the [SerializeField] attribute).

    I'm asking since I usually prefer hiding my variables as private/protected for encapsulation, but still want some of them serialized.
  2. Tautvydas-Zilys


    Unity Technologies

    Jul 25, 2013
    It serializes the exact same fields the normal Unity serialization system serializes. So yes, it will serialize private fields if you mark them with [SerializeField] attribute.
    jeremy_crowell likes this.