If anyone is trying to call the C++ Interface from the Widget’s Blueprint directly, and having trouble compiling correctly, there are at least two ways to go about it.
The first way is to follow the unreal documentation directly, and declare the methods with BlueprintNativeEvent
. But then to override them in C++ , you have to declare them with a _Implementation
suffix. This allows it to be implemented in either BP or C++, but is also a bit ugly.
Luckily, I found this post the unreal forums where all you need to do is add this meta tag to the UINTERFACE
macro: meta = (CannotImplementInterfaceInBlueprint)
. Then declaring the method UFUNCTION(BlueprintCallable)
will expose it and it will call the subclassed implementation!
Edit: It seems I was missing BlueprintType
from the UINTERFACE attributes. Which is needed to actually expose the interface to Blueprint.
So my interface ended up like this:
// This class does not need to be modified.
UINTERFACE(BlueprintType, meta = (CannotImplementInterfaceInBlueprint))
class UMenuInterface : public UInterface
{
GENERATED_BODY()
};
class MULTIPLAYER01_API IMenuInterface
{
GENERATED_BODY()
private:
UFUNCTION(BlueprintCallable)
virtual void Host() = 0;
};