Being able to define UInterface
methods in C++ is great, but they should be accessible from Blueprint too. Otherwise, designers or others who are using Blueprint won't be able to interact with your UInterface
. This recipe shows you how to make a function from an interface callable within the Blueprint system.
Create a
UInterface
calledUPostBeginPlay
/IPostBeginPlay
.Add the following
virtual
method toIPostBeginPlay
:UFUNCTION(BlueprintCallable, Category=Test) virtual void OnPostBeginPlay();
Provide an implementation of the function:
voidIPostBeginPlay::OnPostBeginPlay() { GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, "PostBeginPlay called"); }
Create a new
Actor
class calledAPostBeginPlayTest
.Modify the class declaration so that it also inherits
IPostBeginPlay
:UCLASS() class UE4COOKBOOK_API APostBeginPlayTest : public AActor, public IPostBeginPlay
Compile your project. Inside the editor, drag an instance...