Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

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

  1. klarnorbert


    Jun 2, 2018
    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
    lenneth78, joshcamas and rakkarage like this.
  2. Redux


    Nov 10, 2011
    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.
    lenneth78 and joshcamas like this.
  3. joshcamas


    Jun 16, 2017
    Completely agreed here.
  4. Gambit-MSplitz


    May 16, 2015
    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.