Search Unity

  1. How has 2019.2 and the beta been for you so far? Give us feedback in this thread.
    Dismiss Notice

Will JSON be able to serialize private fields?

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

  1. AnomalusUndrdog

    AnomalusUndrdog

    Joined:
    Jul 3, 2009
    Posts:
    1,486
    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

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    6,264
    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.