Using the UFUNCTION macro
The UFUNCTION
macro can be placed above the line of standard C++ function declarations. As with the UPROPERTY
macro, UFUNCTION
also has its specifiers and metadata to interpret the use of the functions.
The UFUNCTION syntax
Let’s first check out the UFUNCTION
syntax:
UFUNCTION([specifier1, specifier2, …], [meta(key1=value, key2=value2, … )]ReturnType FunctionName([param1, param2, …]) [const];
Let’s break it down:
- 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, not for any game logic
The following example demonstrates how to mark the GetHealthPoints()
function to be a UFUNCTION
macro with a displayname
value of Get HP:
UFUNCTION(BlueprintCallable, Category="Player Avatar", Meta=(DisplayName="Get HP")) int GetHealthPoints...