Download

Redeclare identical UInterface twice with different names - can I then Cast it?

Suppose I have two independent plugins.

Suppose I want them both to compile standalone so that I can put them both to the marketplace (or just support them independently by two unrelated teams).

Suppose these two plugins have some bonus ful-plate-set functionality, that involves both of them. So both plugins, being compiled separately and independently, still must be able to communicate if they meet each other.

The first way is delegates, I get it, but delegates are just function calls, generally. So it solves the problem, but the solution will be a little bit noisy and hard to understand/support, as I see it. OOP is nice.

On the other hand there are interfaces, which promise the beautiful and robust solution, just what you need. Class, methods, properties.

The problem is that with delegates it’s directly stated, that equal-load delegates, wherever they were declared and however they were called, are made equal. So delegates with the same parameters always connect.

While reading docs on Interfaces I assume that you can’t redeclare the same interface under another name in another module, and then Cast and use it’s instance “blindly”. Am I getting it right, Interfaces are incapable of blind binding? So they are, effectively, just a weird reproduction of C++ inheritance system?

After reading docs several times I, honestly, could not find the point, where UInterface gives me something above basic C++ inheritance, except that UObject does not really support C++ inheritance, so this UInterface hack allows you to overcome this limitation. Probably. Perhaps some blueprint-related feutures, ok, but will this solve my problem?

So, can I declare two identical interfaces by different names and then Cast? Because if it can it’s a whole different story.

Just a point on this - reflected interfaces do not support properties, at least not reflected properties (UPROPERTY). Native C++ interfaces can have native properties of course, but they will still be missing from a blueprint which wants to implements the interface. Typically UE4 interfaces are purely abstract, and contain no members at all.

Even though class FNames are prefixed by the module name, I doubt you can safely have two interfaces named exactly the same thing. Even if you could though, it would be a pain to work with in the editor where that module name isn’t available, and you’d have no idea which interface you are working with (if it even compiles).