Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

[SerializeField] - "You will almost never need this."

Discussion in 'Documentation' started by klarnorbert, Jun 20, 2018.

  1. klarnorbert

    klarnorbert

    Joined:
    Jun 2, 2018
    Posts:
    3
    Hello guys!

    So I just browsing the Scripting API today, and found this questionable phase under the [SerializeField] documentation: "You will almost never need this.".

    Why would anyone write this? When learning OOP concepts and encapsulation, the first thing you learn is, don't use public variables, use instead setter and getter methods.

    Using [SerializeField], you can expose your private variables to the Inspector, without actually exposing it to other scripts.

    Imho, don't teach bad practices for beginners, especially at the offical API. Please change the documentation to this: "You will almost always need to use this, instead of using public variables (except some rare cases)."
     
    Last edited: Jun 20, 2018
    Sylmerria, joshcamas and rakkarage like this.
  2. Redux

    Redux

    Joined:
    Nov 10, 2011
    Posts:
    112
    Seconded, I use [SerializeField] extensively to manage the public interface of a class against it's serialization. Numerous state members which need serialization but should not be the concern of client code.

    Change this Unity, you're advocating for bad choices, and from a position of authority. This should not be in your documentation.
     
    Sylmerria and joshcamas like this.
  3. joshcamas

    joshcamas

    Joined:
    Jun 16, 2017
    Posts:
    421
    Completely agreed here.
     
  4. Gambit-MSplitz

    Gambit-MSplitz

    Joined:
    May 16, 2015
    Posts:
    1,065
    I probably use SerializeField as much as I use any other keyword. Usage depends greatly on the type of project, but "you will almost never need this" has needlessly freaked out a few of my coworkers in the past, so I agree it should probably be removed.
     
  5. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
  6. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    3,611