c++ interface not forcing implementation

anonymous_user_98920181
Wed, 15 Jul 2020 07:50:45 +0000
UI

So I created a grabbable object interface with a simple function named grab in it. I then created an actor class that included the header for my Grabbable interface, then inherited from IGrabbable in my actor class. I switched over to the Unreal editor to compile. I realized I didn’t actually implement the Grab function from my interface, but it compiled just fine.

Not sure if this is a stupid question but, I was always under the impression that interfaces force you to have an implementation of the function. Am I missing something?

#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "GrabbableInterface.generated.h"

// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UGrabbableInterface : public UInterface
{
	GENERATED_BODY()
};

/**
 *
 */
class RUNTIME_API IGrabbableInterface
{
	GENERATED_BODY()

	// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:

	UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Grabbable Object Interface Functions")
		void Grab();
};

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "GrabbableInterface.h"
#include "TestGrabActor.generated.h"

UCLASS()
class RUNTIME_API ATestGrabActor: public AActor , public IGrabbableInterface
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	ATestGrabActor();

protected:
	// Called when the game starts or when spawned
	virtual void BeginPlay() override;

public:

};

3 posts - 1 participant