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?