Course contentsShow
← Unreal Engine Game Development
Lesson 162 of 8803. C++ and UObject ArchitectureFree lesson

Registering Functions for Blueprint and Reflection

You will use UFUNCTION macros to expose C++ methods to the reflection system, enabling their usage in Blueprints and remote procedure calls.

In this lesson, you will learn how to bridge the gap between your C++ logic and the Blueprint visual scripting environment by using the UFUNCTION macro.

The Role of UFUNCTION

By default, your C++ methods are invisible to the Unreal Engine reflection system. This means that even if a method is public, Blueprints cannot see or call it. The UFUNCTION() macro acts as a gateway; when placed above a function declaration in your header file, it instructs the Unreal Header Tool (UHT) to register that method with the reflection system, allowing the engine to track and access it at runtime.

Exposing Logic to Blueprints

To make a function available inside the Blueprint Editor, you must add specific specifiers inside the UFUNCTION macro. The most common specifier is BlueprintCallable, which adds the function to the right-click menu in the Event Graph.

Here is how you would expose a simple health-reset function:

public:
    /** Resets the player health to max. Available in Blueprints! */
    UFUNCTION(BlueprintCallable, Category = "Player Stats")
    void ResetHealth();

Why Specifiers Matter

When you add BlueprintCallable, you aren't just making the function visible; you are telling the engine: "This function is safe to be called by visual scripts."

If you want to allow a Blueprint to override your C++ implementation, you would use BlueprintNativeEvent instead. If you want to create a function that you define in C++ but only implement in Blueprints, you would use BlueprintImplementableEvent.

By choosing the right specifier, you create a clean contract between your high-performance C++ code and the flexible, rapid-prototyping workflow of Blueprints. Remember that every UFUNCTION must be declared within a class that inherits from UObject (or its children like AActor), and the class must be marked with the UCLASS() macro for the reflection system to parse it correctly.

Key Takeaway: The UFUNCTION() macro with specifiers like BlueprintCallable is the essential mechanism that translates your C++ methods into nodes that can be triggered and managed within the Blueprint visual scripting system.