Exposing UStruct Members to Blueprints
In this lesson, you will learn how to make the internal data of your custom C++ structs accessible, editable, and visible within the Unreal Editor’s Blueprint graphs.
The Role of UPROPERTY
By default, C++ members inside a USTRUCT are invisible to the Unreal reflection system. Even if your struct is declared with USTRUCT(BlueprintType), the individual variables (members) inside that struct will not appear as pins in your Blueprint nodes unless you explicitly mark them with the UPROPERTY macro.
Think of the USTRUCT as a container; the UPROPERTY macro acts as the "key" that tells the reflection system to generate the necessary metadata for the editor to recognize that specific piece of data.
Implementation Example
To expose a member, you simply place the UPROPERTY macro above the variable declaration within your struct. You must provide at least one specifier, such as EditAnywhere or BlueprintReadOnly.
USTRUCT(BlueprintType)
struct FCharacterStats
{
GENERATED_BODY()
// This member will be visible and editable in Blueprints
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Stats")
float Health;
// This member will be visible but cannot be changed via Blueprint nodes
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Stats")
float MaxMana;
};
Why it Matters
When you use UPROPERTY inside a struct, you gain two major benefits:
- The Details Panel: If you have a variable of type
FCharacterStatsin an Actor, the properties marked withEditAnywherewill appear in the Details Panel, allowing designers to tweak values without touching code. - Blueprint Pins: When you break or make this struct in the Blueprint Event Graph, the nodes will now show pins for
HealthandMaxMana. Without theUPROPERTYmacro, those pins would be missing, rendering the data inaccessible to your visual scripting logic.
Always ensure your struct is marked as BlueprintType at the top level; otherwise, the internal UPROPERTY specifiers will not function as expected within the Blueprint system.
Key Takeaway: Adding the UPROPERTY macro to your struct members is the mandatory step to bridge the gap between your C++ data structure and the Blueprint graph’s visual interface.