Hi,
I cannot get to compile my code, because I’m fighting with the Interface system.
The only difference in my method is that now I am using the “UnrealInterface” as the base class, instead of an empty class.
I only want to use the Interface in C++, so I would prefer not to mark my functions as BP Native or Implementable events.
I have created a test project to make things easier.
MyInterface: The Interface.
MyTriggerVolume: The Actor that calls the MyInterface function.
TargetActor: The Actor that implements MyInterface.
Here is my code:
MyInterface.h
#include "CoreMinimal.h"
#include "MyInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI, meta = (CannotImplementInterfaceInBlueprint))
class UMyInterface : public UInterface
{
GENERATED_BODY()
};
class INTERFACETEST_API IMyInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
virtual void RunInterfaceTEST() = 0;
};
MyTriggerVolume.cpp
#include "MyTriggerVolume.h"
#include "MyInterface.h"
void AMyTriggerVolume::OnTiggerOverlap(AActor* InActor)
{
IMyInterface* MyInterface = Cast<IMyInterface>(InActor);
if (MyInterface != nullptr)
{
MyInterface->Execute_RunInterfaceTEST(InActor);
}
}
TargetActor.h
#include "MyInterface.h"
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TargetActor.generated.h"
UCLASS()
class INTERFACETEST_API ATargetActor : public AActor, public IMyInterface
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ATargetActor();
virtual void RunInterfaceTEST() override;
};
TargetActor.cpp
void ATargetActor::RunInterfaceTEST_Implementation()
{
}
Compile Error message:
\Documents\Unreal Projects\InterfaceTEST\Source\InterfaceTEST\MyTriggerVolume.cpp(21): error C2039: 'Execute_RunInterfaceTEST': is not a member of 'IMyInterface'
\documents\unreal projects\interfacetest\source\interfacetest\MyInterface.h(19): note: see declaration of 'IMyInterface'
\Documents\Unreal Projects\InterfaceTEST\Source\InterfaceTEST\TargetActor.cpp(15): error C2039: 'RunInterfaceTEST_Implementation': is not a member of 'ATargetActor'
\documents\unreal projects\interfacetest\source\interfacetest\TargetActor.h(11): note: see declaration of 'ATargetActor'
1>ERROR : UBT error : Failed to produce item: \Documents\Unreal Projects\InterfaceTEST\Binaries\Win64\UE4Editor-InterfaceTEST.pdb
1> Total build time: 17.16 seconds (Local executor: 0.00 seconds)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(41,5): error MSB3075: The command ""C:\Program Files\Epic Games\UE_4.16\Engine\Build\BatchFiles\Build.bat" InterfaceTESTEditor Win64 Development "\Documents\Unreal Projects\InterfaceTEST\InterfaceTEST.uproject" -waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have tried several other solutions found on the net, but apparently none of them worked.
At this point I would ask if anyone knows the correct way to create, implement and call a C++ only interface?
Thanks!