UPROPERTY pointers cannot be interfaces

I have an interface which is defined like this:

class UMyInterface : public UInterface

class IMyInterface

	virtual void MyFunc();

That already works. Now I have a class that inherits from both: Actor and MyInterface:

class AMyClass : public AActor, public IMyInterface

Now to the actual problem. I’d like to have a variable of the type IMyInterface* (in some other class):

    UPROPERTY(BlueprintReadWrite, Category = "My category")
    IMyInterface* MyActor;

MyActor should be spawned at some point later in the game by World->SpawnActor(…). However what I get is a error saying: “UPROPERTY pointers cannot be interfaces”.

I feel like I’m misunderstanding smth. basic here. Is this not a way to work with interfaces? What’s the proper way of implementing a case like this?

I’m not sure what the underlying implementation of UInterfaces are, but I suspect it would be an abstract class, therefore you cannot create an instance of one. You can only check whether a specific instance implements that interface.

Actually having an instance of the interface is not a problem. Just it being a UPROPERTY does not work.

See my other answer about this here.

I have also requested this as a feature at their forum here.

To be honest, I’ve seen your answer but was still hoping to find a solution to this :slight_smile:

I couldn’t accept this myself at first either. The first thing you think is of course what did I misunderstand, this must be possible to do in a modern game engine in 2014. But unfortunately I don’t think there is a solution to this at the moment.

The proper unreal engine way to implement this if you need an UObject or Actor is at the moment to use dynamic casts. Just look at their code examples or even the game engine code itself.

It’s kinda weird but they really missed the main advantages of interfaces with the current design. If you agree with me you can support my request at their forum or write your own.

This actually works ! Thx , but how can i expose this to blueprint ?

here is my way of calling a UInterface function

in .h

TScriptInterface<IIPropertyBound> upperBound;

in .cpp

IIPropertyBound* bound = Cast<IIPropertyBound>(upperBound->_getUObject());
float upperBoundValue = bound->Execute_GetBoundValue(upperBound->_getUObject());