Subobject Replication for Blueprint Child Class

First off YES you can replicate UObject classes so long as you do what is needed to make them replicate, with that out of the way here is the problem I have uncovered. I can setup any UObject I want to replicate in C++ and it does it well with all properties and even sub-sub objects can replicate. However if I create a new Blueprint Object from that same UObject that replicates so well in code and give it new properties that also need to replicate, than those new properties do not replicate at all. I can add a RepNotify to them and the rep notify only gets called on the server. The Subobject exists on both the server and the client, and all the properties that are setup to replicate in C++ replicate just fine, but none of the added blueprint properties do.

My current setup for this is to override the IsSupportedForNetworking() function
Second Step AActors, UActorComponents override the ReplicateSubobjects function
This replicates the subobjects one at a time or using a for loop if they are in an array.

Component CPP


/**
* Setup Property replication
*/
void USubObjectComponent::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
        Super::GetLifetimeReplicatedProps(OutLifetimeProps); DOREPLIFETIME(USubObjectComponent, subObjects);
}

/**
* Allows Subobject replication on a UObject, must be explicitly called from owning object.
* @param Channel
* @param Bunch
* @param RepFlags  */
  bool USubObjectComponent::ReplicateSubobjects(class UActorChannel *Channel, class FOutBunch *Bunch, FReplicationFlags *RepFlags)
{
    bool wroteSomething = Super::ReplicateSubobjects(Channel, Bunch, RepFlags); for (UMySubObject * subObject: this->subObjects)
    {
        if (subObject!= nullptr && !subObject->IsPendingKill())
        {
            wroteSomething |= Channel->ReplicateSubobject(subObject, *Bunch, *RepFlags);  
            // sub-sub object replication, it works!
            wroteSomething |= subObject->ReplicateSubobjects(Channel, Bunch, RepFlags);
        }
     }
    return wroteSomething;
}

So I am continuing to investigate this as it would be quite valuable. I have Run through the Replicate Subobject function and spotted that the Added Blueprint Properties are in fact in the object’s layout… why they are not being set for the blueprint class is beyond me at the moment. I created a subclass of my UObject in C++ and setup the replication, it works perfectly with the same variabled that where added in the Blueprint Version. Any Insight on this would be helpful, or even just feedback.

I also find this problem,any help?

Wow I forgot I posted this so long ago but yes! I did find a solution which was answered on UE4 Answer HUB. Basically you just need to add the following big of code in the “GetLifetimeReplicatedProps” function:



void UNetworkObject::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
    Super::GetLifetimeReplicatedProps(OutLifetimeProps);

    UBlueprintGeneratedClass * bpClass = Cast<UBlueprintGeneratedClass>(this->GetClass());
    if (bpClass != nullptr)
    {
        bpClass->GetLifetimeBlueprintReplicationList(OutLifetimeProps);
    }
}
​​​​​​​

1 Like