Interface pointer as UPROPERTY

I have an ABall class, which simply resembles a ball.

I have an IBallCarrier interface, and whoever implements that interface should be able to carry the ball.

This means, that ABall can be carried by some actor. Now at the moment I have an AActor* Carrier, but it looks like good design to me to make this IBallCarrier* Carrier instead. However, this is apparantly not allowed:

UPROPERTY pointers cannot be interfaces

Is there a specific reason for this, and is there a workaround?

As far as I know there is no typesafe solution for this as long as UObject or AActor are involved. I searched for some time before I came to this conclusion. It’s kinda weird design decision to not having interfaces as we know them from C#, Java or similar. Interfaces in unreal is confusing since they are not used as normal interfaces. They are used to cast actors from the world to see if we can perform different actions. E.g. is this actor “clickable”, then we can cast it to your interface “IClickable”.

Obviously this will result in more dirty non typesafe code and even code duplications all over the application in form of if clauses and dynamics casts, but that’s how the engine works. You can see this in all official examples including the shooter game and strategy game. Also see my old post about this here. Rama answered this question and he knows the engine pretty well.

So short practical answer is: You must use dynamic casts as far as I’m concerned when using actors or uobjects. If you use normal c++ classes however you can use smart pointers or just old fashion “new” and “delete” with normal c++ interfaces. You can also spawn actors into your level and store a normal c++ interface pointer to it but be careful that the actor isn’t removed, because a call to a removed actor will result in a crash.