C++ interfaces? Correct format won't compile

Hey all, I’ve been tackling communication between C++ actors for a while now, and I’m working on making interfaces work. I’ve followed the guide that posted and the docs, and it won’t work.

I think the problem is that it won’t recognize a UINTERFACE as a class. Also, I get the error
cannot open source file “FuncitonHandling.generated.h”" and I’m not really sure why… Any help would be appreciated, I’ve been stuck on this for hours.

FunctionHandling.h

#pragma once

#include "FunctionHandling.generated.h"

UINTERFACE(Blueprintable)
class UFunctionHandling : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IFunctionHandling
{

	GENERATED_IINTERFACE_BODY()

public:

	UFUNCTION(BlueprintImplementableEvent, BlueprintCallable, Category = "Functions")
		FVector Move();


};

FunctionHandling.cpp

#include "Thesis_Test_002.h"
#include "FunctionHandling.h"

UFunctionHandling::UFunctionHandling(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{

}

I believe with the newer versions of UE4, you need to have the constructor definition inside the .h file.

UFunctionHandling(const FObjectInitializer& ObjectInitializer);

Not sure where this should go, but I tried placing it in a few places like in the UINTERFACE, outside of it, etc, but it didn’t work.

I keep getting the error “cannot open source file “FunctionInterface.generated.h”” which I assume is causing all of the rest of the problems.

Try this… Close the solution. Go into the folder location where the VS solution is, and you’ll see an “Unreal Engine Project File”. Right click on it and select “Generate Visual Studio project files”

Hey,

Your error list shows “OtherCompilationError(5)”. If you switch to the Output tab, you should be able to find the specific error that is causing this to show. Please post a screenshot of your output tab to provide more information.

I’ve actually found a tutorial that sort of works. I got to the part where I had to implement the interface and that’s where something’s gone wrong. I also get the OtherCompilationError (5), so I’ll add that as well.

FunctionInterface.h

#pragma once

#include "FunctionInterface.generated.h" 

UINTERFACE(Blueprintable, MinimalAPI)
class UFunctionInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IFunctionInterface
{
	GENERATED_IINTERFACE_BODY()

public:

	UFUNCTION(BlueprintCallable,BlueprintNativeEvent, Category = "Functions")
		float FunctionFloat01();


};

FunctionInterface.cpp

#pragma once

#include "Thesis_Test_002.h"
#include "FunctionInterface.h"

UFunctionInterface::UFunctionInterface(const FObjectInitializer& ObjectInitializer):Super(ObjectInitializer)
{

}

BaseTest.h

#pragma once

#include "GameFramework/Actor.h"
#include "FunctionInterface.h"
#include "BaseTest.generated.h"

UCLASS()
class THESIS_TEST_002_API ABaseTest : public AActor, public IFunctionInterface
{
	GENERATED_BODY()
	
public:	
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Functions")
		float InterfaceFloat;
	ABaseTest();
	virtual void BeginPlay() override;
	virtual void Tick( float DeltaSeconds ) override;

	
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "MyCategory")
		virtual float FunctionFloat01_Implementation() override;
	
};

BaseTest.cpp

#include "Thesis_Test_002.h"
#include "BaseTest.h"

ABaseTest::ABaseTest()
{
 		PrimaryActorTick.bCanEverTick = true;

	InterfaceFloat = 2;

}

void ABaseTest::BeginPlay()
{
	Super::BeginPlay();
	
}

void ABaseTest::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

float ABaseTest::FunctionFloat01_Implementation()
{
	return InterfaceFloat;
}

And here is the output:

For some reason I couldn’t post a comment to you, but I could post an answer, could you look at my updated post below?

Looking at the output log and the code provided, the error appears to be caused by the FunctionFloat01_Implementation declaration in BaseTest.h. As stated in line 5 of the output, the function cannot be declared as virtual function and a BlueprintNativeEvent at the same time. If you are trying to override the function in a child class then I would remove BlueprintNativeEvent from BaseTest and only include it in the overridden children.

Cheers