x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

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.

Product Version: UE 4.15
Tags:
more ▼

asked Apr 20 '17 at 03:41 PM in C++ Programming

avatar image

MartinL_Lucid
26 3 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Apr 20 '17 at 04:50 PM

avatar image

Wurmloch83
581 14 12 37

avatar image MartinL_Lucid Apr 21 '17 at 08:28 AM

Yes, that was the issue. I looked at Rama's wiki entry on Interfaces (https://wiki.unrealengine.com/Interfaces_in_C%2B%2B) and that defines the constructor in a cpp file. All working now. Thanks.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question