Added simple UInterface to ShooterGame, now getting linker error

Hi. I have added a simple interface to the ShooterGame sample (InterfacePickupable.h):

#pragma once

#include "InterfacePickupable.generated.h"

UINTERFACE()
class UInterfacePickupable : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IInterfacePickupable
{
	GENERATED_IINTERFACE_BODY()
};

And made AShooterPickup inherit from this new interface:

// Base class for pickup objects that can be placed in the world
UCLASS(abstract)
class AShooterPickup : public AActor, public IInterfacePickupable
{
	GENERATED_UCLASS_BODY()

And now I’m getting a linker error regarding the constructor of the UInterfacePickupable class:

[1/4] Compile ShooterGame.generated.cpp
[2/4] Compile Module.ShooterGame.cpp
ShooterGame.generated.cpp
Module.ShooterGame.cpp
[3/4] Link UE4Editor-ShooterGame-Win64-DebugGame.dll
[4/4] Link UE4Editor-ShooterGame-Win64-DebugGame.lib
   Creating library D:\ShooterGame\Intermediate\Build\Win64\UE4Editor\DebugGame\UE4Editor-ShooterGame-Win64-DebugGame.lib and object D:\ShooterGame\Intermediate\Build\Win64\UE4Editor\DebugGame\UE4Editor-ShooterGame-Win64-DebugGame.exp
   Creating library D:\ShooterGame\Intermediate\Build\Win64\UE4Editor\DebugGame\UE4Editor-ShooterGame-Win64-DebugGame.suppressed.lib and object D:\ShooterGame\Intermediate\Build\Win64\UE4Editor\DebugGame\UE4Editor-ShooterGame-Win64-DebugGame.suppressed.exp
ShooterGame.generated.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl UInterfacePickupable::UInterfacePickupable(class FObjectInitializer const &)" (??0UInterfacePickupable@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function "void __cdecl InternalConstructor<class UInterfacePickupable>(class FObjectInitializer const &)" (??$InternalConstructor@VUInterfacePickupable@@@@YAXAEBVFObjectInitializer@@@Z)
dbsbuild : error : aborting build on error (1120)
D:\ShooterGame\Binaries\Win64\UE4Editor-ShooterGame-Win64-DebugGame.dll : fatal error LNK1120: 1 unresolved externals
ERROR : UBT error : Failed to produce item: D:\ShooterGame\Binaries\Win64\UE4Editor-ShooterGame-Win64-DebugGame.dll

What am I doing wrong ?

Thanks.

I had this issue, too. I could not find the cause of this, but I have a workaround. Add the following code:

 UINTERFACE()
 class UInterfacePickupable : public UInterface
 {
     GENERATED_UINTERFACE_BODY()
 };
// insert this:
inline UInterfacePickupable::UInterfacePickupable(const class FObjectInitializer& ObjectInitializer)
    : Super(ObjectInitializer)
{}
 
 class IInterfacePickupable
 {
     GENERATED_IINTERFACE_BODY()
 };

I believe this code should be automatically generated, and I suspect this is a bug in the UHT. Maybe you should move this question to the bug reports section to get epics attention.

1 Like

Yes, that was the issue. I looked at Rama’s wiki entry on Interfaces (A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums) and that defines the constructor in a cpp file. All working now. Thanks.