Download

Trying to implement UInterface

Hi,

i’m trying to get an interface working. I read ramas Tutorial and i also took a look into the StrategyGame example. I created the UInterface by adding UObject with the Wizard and renaming it. But i’m not able to get it working… I looked through the answer hub, but i couldn’t find a solution that’s working for me. This is my code:

SelectionInterface.h


#pragma once

#include "SelectionInterface.generated.h"

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

class ISelectionInterface
{
	GENERATED_IINTERFACE_BODY()

};

I removed everything, and the error is still there. The .h file is nowhere included, there are only the few lines you see above.
This is the error i get:



1>------ Build started: Project: RTS, Configuration: Development_Editor x64 ------
1>  Compiling game modules for hot reload
1>  Performing 2 actions (4 in parallel)
1>  RTSPlayerController.cpp
1>  [2/2] Link UE4Editor-RTS-9077.dll
1>     Creating library D:\Unreal Projects\RTS\Intermediate/Build/Win64\UE4Editor\Development\UE4Editor-RTS-9077.lib and object D:\Unreal Projects\RTS\Intermediate/Build/Win64\UE4Editor\Development\UE4Editor-RTS-9077.exp
**1>RTS.generated.cpp.obj : error LNK2019: unresolved external symbol "public: __cdecl USelectionInterface::USelectionInterface(class FObjectInitializer const &)" (??0USelectionInterface@@QEAA@AEBVFObjectInitializer@@@Z) referenced in function "void __cdecl InternalConstructor<class USelectionInterface>(class FObjectInitializer const &)" (??$InternalConstructor@VUSelectionInterface@@@@YAXAEBVFObjectInitializer@@@Z)
1>D:\Unreal Projects\RTS\Binaries\Win64\UE4Editor-RTS-9077.dll : fatal error LNK1120: 1 unresolved externals**
1>  -------- End Detailed Actions Stats -----------------------------------------------------------
1>ERROR : UBT error : Failed to produce item: D:\Unreal Projects\RTS\Binaries\Win64\UE4Editor-RTS-9077.dll
1>  Total build time: 3,59 seconds
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets(37,5): error MSB3073: The command ""C:\Program Files\Epic Games\4.10\Engine\Build\BatchFiles\Build.bat" RTSEditor Win64 Development "D:\Unreal Projects\RTS\RTS.uproject" -rocket -waitmutex -2015" exited with code -1.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


The strange thing is: If i don’t change anything in the project and compile it again, the Output log says “Target is up to date” and no errors (but also no update ingame). If i then change any line (doesn’t matter where or what) the error appears again. Compiling again → “Target is up to date”, no error and so on…

Would be cool if someone has got a solution!

Okay, now after dinner i tried it again. I implemented the .cpp file and now i’m using the normal override function, instead of the …]Implementation function. This is working now.
But how is it done in the StrategyGame example? There is only the .h file. The function is then called via Execute
…]. Does anyone has got an idea or an explanation?

I am on Linux Mint 17.1

Sorry to bump this post but I cannot for the life of me get even a minimal sample of a c++ interface to compile.
I always end up with the error ERROR: UBT ERROR: Failed to produce item: [PATH TO PROJECT BINARIES]/libUE4Editor-MyProject2-28322.so… It looks like a linker error, but how am I supposed to know what to fix from that? I tried doing a manual make with VERBOSE=1 and that didn’t help with information either.

I tried the code on the wiki here https://wiki.unrealengine.com/Interfaces_in_C%2B%2B and it doesn’t compile either.

Everything else works and compiles just fine (uclass, ustructs, uproperty, ufunction) until I try the minimal uinterface sample here:
#pragma once

#include “MyInterface.generated.h”

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

class IMyInterface
{
GENERATED_IINTERFACE_BODY()
};

which is basically like the one in the OP. However, the OP has a useful error message, and given it, I tried implementing the UMyInterface constructor in the implemetation file. as such:
#include “MyProject2.h”

UMyInterface::UMyInterface(const class FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer)
{
}

still to no avail. The OP also made reference to the StrategyGame example, indicating that it might have some example of use. So I went to find it, only to discover it can only be gotten from a “launcher” and that “launcher” is windows only. So after about an hour of trying to find someone with a windows machine who would let me download, compile and run UE4 only to be rebuffed I have decided to seek some help.
I have only been using UE4 for about 5 days so this might be a stupid questions… but It’s been about three hours on this one thing. Please help end the nightmare.