Calling Blueprint-defined interface functions from C++

While the previous recipes have focused on C++ being usable in Blueprint, such as being able to call functions from C++ in Blueprint, and override C++ functions with Blueprint, this recipe shows you the reverse: calling a Blueprint-defined interface function from C++.

How to do it...

  1. Create a new UInterface called UTalker/ITalker.
  2. Add the following UFUNCTION implementation:
    UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Talk)
    void StartTalking();
  3. Provide a default empty implementation inside the .cpp file:
    void ITalker::StartTalking_Implementation()
    {
    
    }
  4. Create a new class based on StaticMeshActor.
  5. Add #include and modify the class declaration to include the talker interface:
    #include ...

Get Unreal Engine 4 Scripting with C++ Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.