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. 

How to create a UINTERFACE

Creating a banal 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!

Product Version: UE 4.7
Tags:
more ▼

asked Jun 07 '15 at 12:54 PM in C++ Programming

avatar image

codx
8 1 2 4

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

1 answer: sort voted first

Yeah, creating Interface is not as easy as it should (meaning, it should be simpler) but it's still pretty easy :

Here is how I implemented one of mine :

 UINTERFACE(MinimalAPI)
 class UMyCheckpoint : public UInterface
 {
     GENERATED_UINTERFACE_BODY()
 };
 
 class MYGAME_API IMyCheckpoint
 {
     GENERATED_IINTERFACE_BODY()
 
     virtual void SaveCheckpoint(int8 aCheckpointID) = 0;
     virtual void LoadCheckpoint(int8 aCheckpointID) = 0;
 };

There is some things to know about IInterface and UInterface, I think Rama explain it best here : https://wiki.unrealengine.com/Interfaces_in_C%2B%2B

Hope this helps!

Mick

more ▼

answered Jun 07 '15 at 02:00 PM

avatar image

MickD777
2.1k 70 37 259

avatar image codx Jun 07 '15 at 02:07 PM

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

avatar image MickD777 Jun 07 '15 at 02:15 PM

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.

avatar image codx Jun 07 '15 at 02:29 PM

Well you sure helped, I would never imagine that the code would be generated at compile time!! Thank you very much!

Unfortunately I encountered other errors... If I don't ask too much can you please give me a hint?

here is the .h

 #pragma once
 
 #include "GenericSwitch.generated.h"
 
 UINTERFACE(MinimalAPI)
 class UNIDUNGEON_API UGenericSwitch : public UInterface
 {
     GENERATED_UINTERFACE_BODY()
 };
 
 class UNIDUNGEON_API IGenericSwitch
 {
     GENERATED_IINTERFACE_BODY()
 public:
     /*UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Switch)
         int32 statesCount = 2;
     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Switch)
         int32 currentState = 0;
 
     UFUNCTION(BlueprintCallable, Category = Switch)
         virtual void Increment();
     UFUNCTION(BlueprintCallable, Category = Switch)
         virtual void Decrement();*/
 
     virtual int32 GetStatesCount() = 0;
     virtual int32 GetCurrentState() = 0;
 };

here are the compiler errors:

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

avatar image MickD777 Jun 07 '15 at 02:56 PM

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)

avatar image codx Jun 07 '15 at 03:02 PM

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).

Thank you very much for your help!!!

avatar image MickD777 Jun 07 '15 at 03:06 PM

You can accept my answer than :) Have a nice day!

(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