Cannot implement interface function in blueprint inherited from C++

Hello,

To explain my issue I’ll use Basic Code template named “MyProject” in UE 4.12 with basic Interface and AActor object.

C++ code:

MyInterface.h

UINTERFACE(Blueprintable)
class MYPROJECT_API UMyInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IMyInterface
{
	GENERATED_IINTERFACE_BODY()

public:

	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "A")
	void MyEvent(bool& ReturnValue);
};

MyActor.h

UCLASS()
class MYPROJECT_API AMyActor : public AActor, public IMyInterface
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	AMyActor();

	// Called when the game starts or when spawned
	virtual void BeginPlay() override;
	
	// Called every frame
	virtual void Tick( float DeltaSeconds ) override;

	virtual void MyEvent_Implementation(bool& ReturnValue) override;
	
};

In content browser I Create Blueprint Class based on MyActor, let’s call it MyActorCPP.
Now in MyActorCPP blueprint there’s an implementable MyEvent function, but after implementing it there’s a compile error:

"Cannot override 'MyInterface::MyEvent' at My Event which was declared in a parent with a different signature".

It only happens when function declaration contains a reference. (MyActorCPP.jpg)

What’s strange is that when i create new Blueprint class based on AActor and add MyInterface through Class Settings, MyEvent can be compiled without errors. (MyActorBP.jpg)

Does that mean I cannot implement C++ interface functions in Blueprints this way, or is it a bug?

After playing around with this I have come to the conclusion that you can’t mix and match C++ and blueprint interfaces if they include BlueprintNativeEvents. Any interface with BlueprintNativeEvent cannot be used by a C++ class. It must be added to the blueprint actor.

Whether this is a bug or not, I don’t know.

As a workaround you can remove the C++ interface from AMyActor. In BeginPlay() you can add the following line:

check(GetClass()->ImplementsInterface(UMyInterface::StaticClass()));

This will ensure that any blueprint class that extends this class or its children implements the interface in blueprints (by ensure I mean hard crash if the developer forgot to add the interface in blueprints).

Thank you Shohei,
I’ve checked 4.8.3 and it has same issue. Looks like it’s not a bug, but more like a missing feature or intended behaviour. I’ll try your workaround and change my approach. Thanks again!

See the solution this user found here. It seems like he managed to get a similar setup working.

Thanks, though it seems that this does not work for methods with references, so the only way to implement value returning interface functions is to add that interface through Class Settings. The conclusion is you either implement an interface in C++ OR Blueprints, not both in the same class. At least when you want your interface functions to return a value. Anyway, thank you very much! :slight_smile: