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...
- Create a new
UInterface
calledUTalker
/ITalker
. - Add the following
UFUNCTION
implementation:UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = Talk) void StartTalking();
- Provide a default empty implementation inside the
.cpp
file:void ITalker::StartTalking_Implementation() { }
- Create a new class based on
StaticMeshActor
. - 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.