Properties and Accessors🔗
Script Properties🔗
Properties can be added as variables in any script class. The initial value of a property can be specified in the class body.
By default any plain property you declare can only be used from script and is not accessible to blueprint or in the editor.
Editable Properties🔗
To expose a property to unreal, add a UPROPERTY()
specifier above it.
Note: It is not necessary to add
EditAnywhere
to properties in script. Unlike in C++, this is assumed as the default in script.
To be more specific about where/when a property should be editable from the editor UI, you can use one of the following specifiers:
Blueprint Accessible Properties🔗
When a property is declared with UPROPERTY()
, it also automatically becomes usable within blueprint:
To limit the blueprint from reading or writing to the property, you can use one of the following specifiers:
Note: It is not necessary to add
BlueprintReadWrite
to properties in script. Unlike in C++, this is assumed as the default in script.
Categories🔗
It can be helpful to specify a Category
for your properties.
Categories help organize your properties in the editor UI:
Property Accessor Functions🔗
Script methods that start with Get..()
or Set..()
can use the property
keyword to allow them to be used as if they are properties.
When the property value is used within other code, the appropriate Get or Set function is automatically called:
Property Accessors in C++ Binds🔗
Note that all C++ binds can be used as property accessors regardless.
That means that any C++ function that starts with Get...()
can be accessed as a property.
This lets you access things such as Actor.ActorLocation
as a property.
For C++ binds, both forms are valid, so ActorLocation
and GetActorLocation()
produce the same result.
Access Modifiers🔗
If you want a property or function to be private
or protected
in script, each individual property needs to be specified that way:
Properties that are private
cannot be accessed at all outside the class they are declared in.
Properties that are protected
can only be accessed by the class itself and its children.
Tip: Access modifiers work for functions as well as for properties.