Creating a trivial interface seen by the Unreal Editor is literally driving me crazy…
I googled a lot and found nothing useful for 4.7.
Can anyone tell me how the hell do I create an interface? It’s a foundamental thing in programming, it’s not acceptable to renounce using it!
I already read this tutorial and it’s extremely easy as you say. The problem is that from the editor I cannot create a new class inheriting from UInterface so the .generated.h defining the UINTERFACE() macro is not created and if I extend simply UObject in order to edit it later the .generated.h does not contain the macro, instead has #undef UINTERFACE
THAT is the real problem, setting up the two classes needed is pretty straightforward
Ok, don’t worry, it’s pretty easy Yes the tutorial do not mention how, but it automatically generates once you compile. I was asking myself the same question when first created it. Here is my COMPLETE .h :
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "JotunnCheckpoint.generated.h"
UINTERFACE(MinimalAPI)
class UJotunnCheckpoint : public UInterface
{
GENERATED_UINTERFACE_BODY()
};
class MYGAME_API IJotunnCheckpoint
{
GENERATED_IINTERFACE_BODY()
virtual void SaveCheckpoint(int8 aCheckpointID) = 0;
virtual void LoadCheckpoint(int8 aCheckpointID) = 0;
};
And my complete .cpp:
// Fill out your copyright notice in the Description page of Project Settings.
// Fill out your copyright notice in the Description page of Project Settings.
#include "Jotunn.h"
#include "JotunnCheckpoint.h"
UJotunnCheckpoint::UJotunnCheckpoint(const class FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
Just create a new class using UObject, then replace for UInterface.
Replace the MYGAME_API for yours (if your project is name MyGreatGame, it should be MYGREATGAME_API )
After that compile your game in Visual Studio and UBT will create the .generated.h for you.
Error 1 error C2487: ‘GetPrivateStaticClass’ : member of dll interface class may not be declared with dll interface d:\unrealengine\unidungeon\source\unidungeon\GenericSwitch.h 13 1 UniDungeon
Error 3 error C2487: ‘GetPrivateStaticClass’ : member of dll interface class may not be declared with dll interface D:\UnrealEngine\UniDungeon\Source\UniDungeon\GenericSwitch.h 13 1 UniDungeon
Error 2 error C2487: ‘UGenericSwitch::{ctor}’ : member of dll interface class may not be declared with dll interface d:\unrealengine\unidungeon\source\unidungeon\GenericSwitch.h 13 1 UniDungeon
Error 4 error C2487: ‘UGenericSwitch::{ctor}’ : member of dll interface class may not be declared with dll interface D:\UnrealEngine\UniDungeon\Source\UniDungeon\GenericSwitch.h 13 1 UniDungeon
Great job!!
I’m now seing further errors because my project’s generated cpp file was declaring a constructor for my interface (I initially created the class as a Ubject, i guess that’s the reason).
Ha, nice one, I had my project with my working interface in 4.7.1, since you had this issue I went ahead and tried to do the same in 4.7.5, and it did the same error as you! After some messing around, I found that the “MinimalAPI” in UINTERFACE was the issue. Looks like they changed that somewhere along the way.
So just use UINTERFACE() instead of UINTERFACE(MinimalAPI)