A Game Design Tip A Day #2 – [Unity C#] SerializeField Attribute

SerializeField is extremely helpful when you have variables you want to see in the Inspector, but you don’t want to make them public. If you’re following good software engineering principles, then you’ll certainly want to keep variables private unless you want them to be directly accessed or modified from other scripts. Or you can be a rebel and make it public anyway, but I’ll be quietly judging you.

tip_a_day_02

Using this attribute, you can build your code in such a way that you keep good encapsulation and data-hiding principles in place while allowing designers and other people who will have access to the script from within the editor to tweak certain values as required. It bestows a glorious amount of control to the programmer, even if it’s a blasphemous Americanism with its evil “z”.

Advertisements