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

Creating Blueprint Callable Functions in C++

Expose C++ logic to the Blueprint visual scripting system using UFUNCTION specifiers to bridge the gap between engine performance and designer accessibility.

Creating Blueprint Callable Functions in C++

In this lesson, you will learn how to bridge the gap between high-performance C++ logic and the flexibility of the Blueprint visual scripting system using the BlueprintCallable specifier.

Why Expose Functions?

While C++ is ideal for complex calculations, memory management, and performance-critical systems, Blueprints are perfect for designers who need to quickly trigger events or tweak gameplay logic. By exposing your C++ functions, you allow designers to call your robust code directly from their Event Graphs, keeping your project organized and accessible.

Implementing the BlueprintCallable Specifier

To make a C++ function accessible in Blueprints, you use the UFUNCTION() macro above your function declaration in the header file. By adding the BlueprintCallable keyword, you tell the Unreal Header Tool (UHT) to generate the necessary code to bridge your function to the editor.

Consider this example where you have a custom health-management system:

// In your Header file (.h)
UFUNCTION(BlueprintCallable, Category = "Combat")
void HealPlayer(float Amount);

By providing a Category, you ensure that your function appears in the correct section of the Blueprint context menu, making it easy for designers to find.

Essential Rules for Implementation

  1. The Header File: Ensure your function is marked with UFUNCTION(BlueprintCallable).
  2. The Source File: You still write the logic in your .cpp file exactly as you would a normal C++ function.
  3. Blueprint Interaction: Once you compile your code, you can right-click anywhere in a Blueprint's Event Graph and search for "HealPlayer." It will appear just like any native Blueprint node.
  4. Parameters: Any parameters you define in your C++ function (like float Amount) will automatically become input pins on the Blueprint node.

By using this approach, you effectively move logic into the high-speed C++ layer while retaining the design-time agility that Unreal Engine is famous for. You no longer have to choose between performance and ease of use; you get the best of both worlds.

Key Takeaway: Use the BlueprintCallable specifier within a UFUNCTION macro to allow Blueprint-based actors to execute your custom C++ logic seamlessly.