Make an interface that is only implementable by C++ classes

Is it possible to make an interface that is only implementable by C++ classes, and not blueprints? I couldn’t find any documentation about the UINTERFACE macro, so I have no idea what I can do with it.

Just declare a regular C++ interface class without the UINTERFACE attribute.

class IMyInterface
{
};

UCLASS()
class UMyObject
    : public UObject
    , public IMyInterface
{
};

Sorry for the delay… I saw your answer pretty long ago, and I tried to implement it…I didn’t really work.

First of all, yes, I could make a normal C++ interface and it wasn’t exposed to blueprints. But it still isn’t perfect.

So the interface is there because I wanted to have a generic AI controller that will be able to control many pawns. So that interface is called IAICharacter, and it is declared like that:
class REAL3DPLATFORMER_API IAICharacter
{

public:
	FORCEINLINE virtual class UBehaviorTree* GetBehaviorTree() const = 0;

};

This is an interface all characters that are expected to have an AI controller should have. So inside of the Possess function in the controller, I wanted to get access to that method I put in the interface. So I wanted to cast the possessed pawn into the interface, and call the method. Here are the kind of casts I used:

	Character = Cast<IAICharacter>(PossessedPawn);
	Character = dynamic_cast<IAICharacter*>(PossessedPawn);
	Character = static_cast<IAICharacter*>(PossessedPawn);    

(Keep in mind that PossessedPawn is the parameter the Possess function takes. And that Character is an IAICharacter pointer.)
So the first one didn’t work because IAICharacter is not a UObject.
The second one didn’t work because Unreal doesn’t allow RTTI…which I personally find kinda stupid, to be honest. But I guess they have their reasons.
The third one didn’t work because…it says it can’t convert from APawn* to IAICharacter*, which actually makes sense.

But if those three casts didn’t work… What can I use?

What you’re trying to do is called down-casting, and it’s bad design. You shouldn’t do it. Either way, a C-style cast should work:

IAICharacter* Character = (IAICharacter*)PossessedPawn;

I forgot to say…I already tried a C-style cast. But it crashes. Probably because C-style casts work in a way where if they succeed, they return the object as the type it is casted to, else they thrown an exception (and Unreal crashes whenever an exception is thrown).

This is not what I want. I want to return a null pointer if it fails, so I can use an if statement to check if it’s safe to use it.
This is basically what dynamic_cast does, but since Unreal doesn’t allow RTTI, I am not able to use.

Coming from C#, it was as easy as adding the “as” operator after the object, and then putting the interface name. It returned null if it failed, and the object as the new type if it succeed. Sounds like dynamic_cast to me, so I don’t see what’s the problem with that (especially that I know Unity supports it without any problem, so it kinda confuses me why Epic decided not to allow using it…).

What do you recommend me do if it’s bad to use downcasting? And if in this case I need to use downcasting, which cast can I use?