A property is a member that provides a flexible mechanism to read, write, or compute the value of a variable.


Creating properties

To create a property press ‘plus’ button on the right side of Class Properties section:

Note: If you can't find this section, check its visibility in the panel 'Hidden script objects' in the bottom of toolbar.


Using properties

The property has ‘set’ and ‘get’ assessors (edit graphs).

Set’ assessor - executing when we set the value of property (has input pin of new value):

Get’ assessor - executing when we get the value (has output pin, must return a value):


Note: ‘Return’ node allways must be linked with sequence connector in get accessor. The value must be returned at the end of code sequence.

You can switch between ‘set’ or ‘get’ assessors by pressing ‘Get’ and ‘Set’ buttons at the top left of edit graph. To disable ‘set’ or ‘get’ assessors use checkboxes near this buttons.



In this example we will debug values when new value will be set or get in property:

Now test it. We get the value, set it again to this property and get the console messages:


Property modifiers

Access modifiers control the access of property for other classes and visibility in inspector window.


public - access is not restricted.

protected - access is limited to the containing class or types derived from the containing class.

internal - access is limited to the current assembly.

protected internal - access is limited to the current assembly or types derived from the containing class.

private - access is limited to the containing type.

const is used to declare a constant field or a constant local. Constant fields can’t be modified.


static modifier is used to declare a static member, which belongs to the type itself rather than to a specific object.

Note: you can’t use non-static variables in static property.

The virtual modifier is used to modify a property and allow for it to be overridden in a derived class. It means that you can create a class ‘A’ with a virtual property and you will be able to override the code of this property in class ‘B’ which derived from class ‘A’.

Render time: 0.02 seconds
137,027 unique visits