In this lesson, you will learn how to make your C++ variables visible and editable inside the Unreal Editor’s Blueprint interface using the UPROPERTY macro.
The Bridge Between C++ and Blueprints
When you define a variable in C++, it is hidden from the Blueprint editor by default. To make it show up in the "Details" panel of an actor, you need to use the UPROPERTY macro. This macro tells the Unreal Reflection System that the variable should be managed by the engine and accessible to designers.
To expose a variable, place UPROPERTY directly above your variable declaration and provide the necessary specifiers inside the parentheses.
Making Variables Editable
The most common specifier you will use is EditAnywhere. This allows you to modify the value of the variable both in the main Level Editor and within the Blueprint Editor.
Consider this example:
UCLASS()
class MYGAME_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// This variable is now visible in the Details panel
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Gameplay Settings")
float MovementSpeed = 600.0f;
};
Understanding the Specifiers
EditAnywhere: Allows you to edit the variable in the Details panel for both placed instances in the level and the Blueprint asset itself.BlueprintReadWrite: Permits your Blueprints to both read the value and update it during gameplay (using "Get" and "Set" nodes).Category: This is optional but highly recommended. It organizes your variable into a specific tab in the Details panel, making your project much easier to navigate as it grows.
By adding these specifiers, you create a bridge that allows non-programmers to tweak your game mechanics without ever touching the C++ source code. This is the foundation of the "Designer-Friendly" workflow in Unreal Engine.
Key Takeaway: Use the UPROPERTY(EditAnywhere, BlueprintReadWrite) macro to expose your C++ variables to the Editor, allowing you to fine-tune game values without needing to recompile your code.