Property exposing
By default, the Object Inspector displays all public member variables of a class unless it's in Debug mode or a private member is explicitly marked with the SerializeField
attribute and in these cases private member variables will be shown too:
However, C# properties will never be displayed by default, either in Release or Debug mode. As discussed in Chapter 1, Unity C# Refresher, C# properties act like accessor functions to a variable. They essentially permit validation on each get
and set
operation because every get
and set
operation entails an internal function call. However, regardless of Unity's limitation in the Object Inspector, it's possible to write an editor extension that will show all properties for a class in the Object Inspector, which allows you to get and set the values directly. This section considers how in more detail. Again, we'll have reason to rely heavily on reflection.
Tip
More information on the
SerializeField...