Interface implementation

Hello, i encountered such a problem if I created an interface and declared the function foo (), then if I inherit a class from this interface and do not implement the function foo (), then there will be no compilation error. Although it should be. It’s look like in C#. If you inherit a class from interface you will need to implement all functions else you will get compilation error. Or in C++ with plural virtual functions the same pattern. Example below:

#pragma once

#include "ReactsToTimeOfDay.generated.h"

UINTERFACE(BlueprintType)
class MYPROJECT_API UReactsToTimeOfDay : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class MYPROJECT_API IReactsToTimeOfDay
{
	GENERATED_IINTERFACE_BODY()
	
public:
	//classes using this interface must implement ReactToHighNoon
	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "MyCategory")
		bool ReactToHighNoon();

	//classes using this interface may implement ReactToMidnight
	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "MyCategory")
		bool ReactToMidnight();

};

#include "ReactsToTimeOfDay.h"
#include "ASkeletalMeshActor.generated.h"

UCLASS()
class AFlower : public ASkeletalMeshActor,  public IReactsToTimeOfDay
{
	GENERATED_BODY()

public:
	/*
	... other AFlower properties and functions declared ...
	*/
	
	//UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "MyCategory")   
	//	bool ReactToHighNoon();
	//	virtual bool ReactToHighNoon_Implementation() override;     <- We should get a compilation error, but not.
	
	
};

The rule only holds up if you declare the functions as pure virtual functions, i.e. “virtual void FunctionName() = 0”.

UFUNCTION() macro cannot be used with pure virtual functions, hence pure virtual functions cannot be extended into blueprints. I don’t think there is any function specifiers for the macro to implement the behaviour you seek, though I haven’t looked into it too much. In that case, the interfaces used in blueprints will only have optional implementations.

If you only use the interface in C++ then pure virtual functions will work just fine and give you compilation errors if you lack an implementation.