Did Interfaces change in 4.7.x?

It seems to be a bit out of date, especially when we now have different syntax for constructors.

Has anyone figured out how to create interfaces in 4.7.x?


#pragma once
 
#include "Interact.generated.h"
 
/** Class needed to support InterfaceCast<IToStringInterface>(Object) */
UINTERFACE(MinimalAPI)
class UInteract : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};
 
class IInteract
{
	GENERATED_IINTERFACE_BODY()
  IInteract(const FObjectInitializer& obj = FObjectInitializer::Get());
  virtual void Interact();
};


#include "ShooterGame.h"
#include "Interact.h"


IInteract::IInteract(const FObjectInitializer& obj)
{

}

void IInteract::Interact()
{

}

But this code results in a linker error


error LNK2019: unresolved external symbol "public: __cdecl UInteract::UInteract(class FObjectInitializer const &)" (??0UInteract@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function "void __cdecl InternalConstructor<class UInteract>(class FObjectInitializer const &)" (??$InternalConstructor@VUInteract@@@@YAXAEBVFObjectInitializer@@@Z)

You need to change the decleration and defenition.



IInteract::IInteract(const FObjectInitializer& obj);

IInteract::IInteract(const FObjectInitializer& obj = FObjectInitializer::Get())
{

}

is a example.


UINTERFACE(Blueprintable, Category = "Event Brain, Interfaces")
class MYGAME_API UTimeOfDayEventInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()

public:
	
};

class ITimeOfDayEventInterface
{
	GENERATED_IINTERFACE_BODY()

public:
	ITimeOfDayEventInterface(const FObjectInitializer & PCIP);

..

};


UTimeOfDayEventInterface::UTimeOfDayEventInterface(const FObjectInitializer & PCIP)
	: Super(PCIP)
{
..
}

// Not sure if this is safe tough, never done it my self but it compiles.
ITimeOfDayEventInterface::ITimeOfDayEventInterface(const FObjectInitializer & PCIP = FObjectInitializer::Get())
{
..
}

Hope it helps. :slight_smile:

Thanks for the help. The problem was that the constructor had to be from USomeInterface not ISomeInterface. I should learn to read.