Each UCLASS
that you declare can have any number of UPROPERTY
declared for it within it. Each UPROPERTY
can be a visually editable field, or some Blueprints accessible data member of the UCLASS
.
There are a number of qualifiers that we can add to each UPROPERTY
, which change the way it behaves from within the UE4 Editor, such as EditAnywhere
(screens from which the UPROPERTY
can be changed), and BlueprintReadWrite
(specifying that Blueprints can both read and write the variable at any time in addition to the C++ code being allowed to do so).
To use this recipe, you should have a C++ project into which you can add C++ code. In addition, you should have completed the preceding recipe, Making a UCLASS – deriving from UObject.
UCLASS
declaration as follows:UCLASS( Blueprintable ) class CHAPTER2_API UUserProfile : public UObject { GENERATED_BODY() public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stats) float Armor; UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Stats) float HpMax; };
UObject
class derivative, and open the Blueprint in the UE4 editor by double-clicking it from the object browser.UPROPERTY
fields:The parameters passed to the UPROPERTY()
macro specify a couple of important pieces of information regarding the variable. In the preceding example, we specified the following:
EditAnywhere
: This means that the UPROPERTY()
macro can be edited either directly from the Blueprint, or on each instance of the UClass
object as placed in the game level. Contrast this with the following:EditDefaultsOnly
: The Blueprint's value is editable, but it is not editable on a per-instance basisEditInstanceOnly
: This would allow editing of the UPROPERTY()
macro in the game-level instances of the UClass
object, and not on the base blueprint itselfBlueprintReadWrite
: This indicates that the property is both readable and writeable from Blueprints diagrams. UPROPERTY()
with BlueprintReadWrite
must be public members, otherwise compilation will fail. Contrast this with the following:BlueprintReadOnly
: The property must be set from C++ and cannot be changed from BlueprintsCategory
: You should always specify a Category
for your UPROPERTY()
. The Category
determines which submenu the UPROPERTY()
will appear under in the property editor. All UPROPERTY()
specified under Category=Stats
will appear in the same Stats
area in the Blueprints editor.UPROPERTY
listing is located at https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Reference/Properties/Specifiers/index.html. Give it a browse.3.149.27.72