Properties

Andrea Alicino
2 min readJun 14, 2021

A property is a member that provides a flexible mechanism for reading, writing, or calculating the value of a private field. This provides easy access to data and promotes security and flexibility of methods.
To use a property, you must declare a private variable and its namesake by convention with the first letter capitalized and define its get and set, representing the possibility of reading (get) and writing (set).

This allows us to maintain the integrity of the data itself since it is not directly accessible being private.
Within get and set, we can also define other elements that must be called when the data is written or read.

There are also auto-properties that don’t need the declaration of a private and associated variable, but we must always explicitly define the set and manage if we want it to be public, private, or protected.

Properties can have several uses, in Unity one of these can be the use of more important variables related to the Manager classes that we write, such as the Game Manager, the UI Manager, and many others. The properties are not serialized directly by the Unity Inspector so they can only be modified by the behavior written in the code. To see them in this tab we must use the DebugMode of the Inspector or write our own Editor script that serializes them.

--

--

Andrea Alicino

Game Developer Unreal Engine/Unity. Computer science graduate. Seeking new opportunities.