COND_InitialOnly replication is not working for UActorComponent how to fix that?

ForceNetUpdate() will not work here. Actually correctly rewriting ReplicateSubobjects did the trick.

bool AMyGameState::ReplicateSubobjects(UActorChannel *Channel, FOutBunch *Bunch, FReplicationFlags *RepFlags)
{
check(Channel);
check(Bunch);
check(RepFlags);

bool WroteSomething = false;

for (UActorComponent* ActorComp : ReplicatedComponents)
{
    if (ActorComp && ActorComp->GetIsReplicated())
    {
        bool bNetInitial = RepFlags->bNetInitial;
        RepFlags->bNetInitial = Channel->ReplicationMap.Find(ActorComp) == nullptr;

        WroteSomething |= ActorComp->ReplicateSubobjects(Channel, Bunch, RepFlags);        // Lets the component add subobjects before replicating its own properties.
        WroteSomething |= Channel->ReplicateSubobject(ActorComp, *Bunch, *RepFlags);    // (this makes those subobjects 'supported', and from here on those objects may have reference replicated)

        RepFlags->bNetInitial = bNetInitial;
    }
}

return WroteSomething;

}

Now COND_InitialOnly works per UObject, not per AActor.

1 Like