How to use UINTERFACE, convert the UInterface to IInterface?


I have had some problems understanding how the interface system is supposed to be used. The UINTERFACE consists of two parts, “UMyInterface” and “IMyInterface”. From what I understand you must use the “UMyInterface” to safely store references/pointers to an interface, e.g. as an UProperty or a TWeakObjectPtr.

Now, how do you access the methods in “IMyInterface” from a pointer of type “UMyInterface”? I understand you can use InterfaceCast but must you really use a dynamic cast when you already know the type?

#Ignore UInterface

Just use InterfaceCast<>


The UInterface is meant only to be a wrapper for the IInterface

do multiple inheritance with IInterface

Ignore UInterface, it is not meant to have functionality of its own :slight_smile:

The comment in the Source code during the Beta went something like this

"/** Class needed to support InterfaceCast<>"

It is just a support structure, the real core is all in the IInterface :slight_smile:


Thanks a lot for helping me understand how the UINTERFACE works.

I have had a lot of struggle understanding this. I also have some comments to EPIC about this. In terms of typesafety this is really dirty. It doesn’t only make the code more error prone and hard to read but also leads to a lot of code duplications in form of if clauses spread all over the application performing dynamic casts and checking for null. Even though it’s unlikely to lead to any major performance issues, it still has impacts on code quality.

@Rama what Design Pattern is being employed?

Also, what “system” is UInterface feeding? I’d guess the property system as I see it being used in calls to ::StaticClass(), aye?

I dont know exactly how IInterface works, and I am not sure what sort of answer you are looking for as to the details of its operation, I hope someone at Epic can answer this question about the inner workings of IInterface!

I do know that it does work and its fast hee hee :slight_smile:



I’m having some trouble with this actually. I create a UInterface and IInterface of my own and implemented it within a blueprint. The UInterface is “Blueprintable”. But in the code whenever I try to cast that object it fails. “Actor->Implements()” works fine. But “InterfaceCast(Actor)” fails…

InterfaceCast has been deprecated

- Cast or dynamic_cast should be used instead.

source: Unreal Engine 4.6 Release Notes | Unreal Engine Documentation