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++.
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 "Talker.h" class UE4COOKBOOK_API ATalkingMesh : public AStaticMeshActor, public ITalker
Also, add the following function to the class declaration:
void StartTalking_Implementation();
Within the implementation, add the following to the constructor:
ATalkingMesh...