Can't compile new UInterface

I’ve been trying to create a C++ interface following this page of the 4.14 documentation to implement user interaction with actors. So, I made a a default UInterface using the Create C++ class wizard in the editor.
The idea is that the Main Character class fires a single line trace to identify an Actor, get the Actor and check whether or not it implements my interface. If it does, fire the event on the Actor.
My interface looks like this;

MainCharacterInteraction.h

#pragma once

#include "MainCharacterInteraction.generated.h"

UINTERFACE(Blueprintable)
class UMainCharacterInteraction : public UInterface
{
	GENERATED_BODY()
};

class MYAPI_API IMainCharacterInteraction
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, BlueprintImplementableEvent, Category = "Player interaction")
	void Interact() const;
};

MainCharacterInteraction.cpp

void AMainCharacterInteractionActor::Interact() const
{

}

Now, the guide itself is quite vague about the implementation side, because it shows how to implement the interface, but not how to give any functionality to it.

MainCharacterInteractionActor.h

#pragma once

#include "CoreMinimal.h"
#include "Interfaces/Character/MainCharacterInteraction.h"
#include "MainCharacterInteractionActor.generated.h"

UCLASS()
class MYAPI_API AMainCharacterInteractionActor : public AActor, public IMainCharacterInteraction
{
    GENERATED_BODY()

public:
    AMainCharacterInteractionActor(const FObjectInitializer& ObjectInitializer);

    UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Player interaction")
    virtual void Interact() const override;
};

So, I’d assume that on the implementation side of the class I should do something like;

MainCharacterInteractionActor.cpp

void AMainCharacterInteractionActor::Interact() const
{

}

But whenever I try and compile this code (either via the Editor -> Compile, or Visual Studio -> Build) it fails with the following error:

MainCharacterInteractionActor.h:17:27: error: only virtual member functions can be marked 'override'

What am I doing wrong?

Hello!

this should be void Interact() const; virtual void Interact() const; in your interface class

and actually you dont need const because you did not return anything…

so go ahed and use

virtual void Interact();

you have right sry… missed that is a blueprintimplementableEvent :slight_smile:
I said then wrong…

So the first problem with that… BlueprintImplementableEvents must be overrided in Blueprint!
This is why we call them BlueprintImplementableEvents

You cant override them… in C++! If you want override in c++ … so you wanna do things both in c++ code and blueprint code you shuld use BlueprintNativeEvent

So you cant declare interface function as blueprintimplementableevent, then override as blueprintnative event…

That must be delcared as blueprintnativeevent and when you override you must override in this form:

virtual void Interact_Implementation() override;

Further Informations about interfaces and UFUNCTION marks:

Thanks for your answer. It didn’t help though;
If I declare the interface function as virtual void Interact(), I get this error: Error: BlueprintImplementableEvents in Interfaces must not be declared 'virtual’

Your answer pushed me in the right direction. Thanks.

As it turns out, the guide I followed was specifically tailored for BlueprintImplementableEvents, what I needed was a BlueprintNativeEvent. For people that might end up with the same issues as me; the trick is that the BlueprintNativeEvent variants magically get some extra methods when creating the events using an interface. Calling these methods should be done using the Execute_ method, which gets generated during compilation.

My code for future reference:

MainCharacterInteraction.h

UINTERFACE(Blueprintable)
class UMainCharacterInteraction : public UInterface
{
	GENERATED_BODY()
};

class MYAPPI_API IMainCharacterInteraction
{
	GENERATED_BODY()

public:
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Player interaction")
	void Interact();
};

MainCharacterInteraction.cpp

#include "MainCharacterInteraction.h"

MainCharacterInteractionActor.h

UCLASS()
class MYAPI_API AMainCharacterInteractionActor : public AActor, public IMainCharacterInteraction
{
    GENERATED_BODY()

public:
    AMainCharacterInteractionActor(const FObjectInitializer& ObjectInitializer);

    UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category="Player interaction")
    void Interact();
    virtual void Interact_Implementation() override;
};

MainCharacterInteractionActor.cpp

AMainCharacterInteractionActor::AMainCharacterInteractionActor(const FObjectInitializer& ObjectInitializer)
{
}

void AMainCharacterInteractionActor::Interact_Implementation()
{
    // Either called via ObjectThatImplementsInterface->ExecuteInteract(Caller); or using a Blueprint override.
}