A Question about TScriptInterface & UInterfaceProperty

I’m new to UE4. When I tried to add an interface property in my class, I found something strange so I did the following test by adding three properties in a class:

UPROPERTY()
FScriptInterface UntypedInterface;

UPROPERTY()
TScriptInterface<UMaterialInterface> TypedInterface;

UPROPERTY()
TWeakObjectPtr<UObject> WeakPointer;

In the class, I tried to extract the properties of those three:

UProperty* UntypedInterface = Class->FindPropertyByName(TEXT("UntypedInterface"));
UProperty* TypedInterface = Class->FindPropertyByName(TEXT("TypedInterface"));
UProperty* WeakPointer = Class->FindPropertyByName(TEXT("WeakPointer"));

Then I set a breakpoint and looked into what they really were in the Watch window and found out:

UntypedInterface is a UInterfacePoperty. That’s ok.

TypedInterface is a UObjectProperty. That confuses me. Isn’t TScriptInterface<> supposed to be a UInterfacePoperty as well? UInterfacePoperty reports the data size of the corresponding field is 16 bytes on 64-bit platforms, while UObjectProperty reports 8 bytes. I don’t think using UObjectProperty for properties of TScriptInterface<> really works. Would anyone please explain it?

On the contrary, the field of TWeakObjectPtr<> is also an instantiated template but does have a UWeakPointerProperty, which is great.

Hello, Isatin

FScripInterface is a utility class that stores the UProperty data for a native interface property. It contains pointers to the contained object itself as well as to the native interface, which is implemented by this object. In fact, these pointers point to the different locations of the same object.
In its turn, TScriptInterface class is a templated version of FScriptInterface, which provides functionality for referencing the interface portion of a UObject that implements a native interface.
Thus, the size difference is logical, since there are two pointers in FScriptInterface and one pointer in TScriptInterface.

Hope this helped!
Good luck!

doubt that this fully explains the situation, but it’s possible what you’re seeing is affected by your choice of template parameter for TScriptInterface. UMaterialInterface is, confusingly, not a UE4 interface type at all. You should use an interface definition class prefixed with ‘I’ as the template parameter for TScriptInterface.

You are absolutely right. UMaterialInterface was randomly picked for the test, and there’s no IMaterialInterface and I didn’t really notice the difference between UInterface and IInterface. I tried again with IInterface_CollisionDataProvider
and this time I did get a UInterfaceProperty. So I don’t have to worry about if FScriptArrayHelper works when I put TScriptInterface in an array. Would you mind converting your comment to an answer that I can accept it?

Sure, done. I didn’t expect this was actually the cause of the issue, but glad it’s sorted it.

Thank you very much.