Using the UPROPERTY macro
The UPROPERTY
macro is placed above the definition of standard C++ class variables to declare Unreal-recognized class properties. The UPROPERTY
macro can have specifiers and metadata for different use cases.
The UPROPERTY syntax
Let’s take a look at the UPROPERTY
syntax:
UPROPERTY([specifier1, specifier2, …], [meta(key1=value, key2=value2, … )]Type VariableName;
Let’s break it down:
- As with function parameters, the specifiers and metadata are enclosed by a pair of parentheses
- The square brackets are used to indicate that the enclosed content is optional
- The ellipsis means that you can include more items
- The metadata keys are only valid in the editor, and not for any game logic
Let’s look at two examples. The first example shows how to define a simple UPROPERTY
variable:
UPROPERTY()bool bHasWeapon;
This example defines the bHasWeapon
property without any specifiers and metadata...