Here are two cases. In the first case, a C++ class inherits from an interface:
class TEST_API AMyActorInheriting : public AActor, public IMyInterface
In the second case, an Actor Blueprint is created, and the IMyInterface is added in the Class Settings:
The interface has a single function for testing, and it has a default implementation.
MyInterface.h:
class INTERFACETEST_API IMyInterface
{
GENERATED_BODY()
public:
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void TestFunction();
//default implementation
void TestFunction_Implementation();
};
MyInterface.cpp
#include "MyInterface.h"
// Add default functionality here for any IMyInterface functions that are not pure virtual.
void IMyInterface::TestFunction_Implementation()
{
GEngine->AddOnScreenDebugMessage(-1, 2.f, FColor::Green, TEXT("TestFunction_Implementation"));
}
I then try to call the interface function after spawning each one:
The BP that inherits the interface from C++ does call the default implementation.
The BP that adds the interface does NOT call the implementation.
What gives? This is a huge difference, and I’d like to know why the interface function does not call the default implementation when it is added to a Blueprint.