In my current understanding, UPROPERTY()
with specifiers (such as EditAnywhere
, VisibleAnywhere
, EditDefaultsOnly
, BlueprintReadOnly
, etc) is used to expose a class field to either Details panel of UE editor or Blueprint.
In my learning journey, I often find some EMPTY UPROPERTY()
(without any specifiers) in UE code base as well as in many other tutorials.
The following example taken from APawn
:
protected:
/** Delegate broadcasted when possessing a new pawn or unpossessing one */
FPawnChangedSignature OnNewPawn;
/** The control rotation of the Controller. See GetControlRotation. */
UPROPERTY()
FRotator ControlRotation;
UPROPERTY(EditDefaultsOnly, Category="Controller|Transform")
uint8 bAttachToPawn:1;
/** Whether this controller is a PlayerController. */
uint8 bIsPlayerController:1;
/** Whether the controller must have authority to be able to call possess on a Pawn */
uint8 bCanPossessWithoutAuthority:1;
/** Ignores movement input. Stacked state storage, Use accessor function IgnoreMoveInput() */
uint8 IgnoreMoveInput;
/** Ignores look input. Stacked state storage, use accessor function IgnoreLookInput(). */
uint8 IgnoreLookInput;
As you can see, some fields are decorated with empty UPROPERTY()
.
QUESTION:
When do we need to apply an empty UPROPERTY()
to a class field? I also often see an empty UFUNCTION()
is applied to member functions. What are they for?
I heard (but not quite understand) that it is about reflection and garbage collection. Could you elaborate more on these parts as well because I am still confused in understanding how we decide whether a field needs an empty UPROPERTY()
or a member function needs an empty UFUNCTION
.