Replication of TScriptInterface C++

TScriptInterface<…> does not currently get replicated by UE4. I actually think it should give an error when you try to do it, but it just silently fails.

Anyway, TScriptInterface<…> is basically just two things, a pointer to your UObject, and then a cached pointer to the Interface part of your UObject that you’re interested in.

The way I would do it right now, given the current limitations, would be to replicate a regular UObject or AActor pointer as a private property, and give access to getting/setting it through public members which only allow TScriptInterface<…> as the argument. The getter would cast from the UObject property to the interface that you want. Enforcing it this way would reduce the chances that a mistake is made elsewhere in the code.

Hi!

I have problems with getting my interface to replicate.
I have a BaseItemInterface and different Items that implements the interface. I try to replicate the interface something like this:

UPROPERTY(Replicated)

TScriptInterface< BaseItemInterface > MyInterface;

It doesnt work.

But when I replicate my raw Item class, ex. ToolItem

UPROPERTY(Replicated)

ToolItem* MyItem;

It works for that object.

Can UE4 handle Interface objects Replication or do I need to add some more code anywhere? I’ve done the bReplicates = true & DOREPLIFETIME(YOUR_CLASS_NAME, PropName); thingy according to A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

Thanks!

Thanks for clarifying that, it make sense.
I’ll have to implement some sort of type translation as you mentioned.