Knowledge Base: Using the Replicated SubObjects List

Using the Replicated SubObjects List
This article was written by Alex K
Currently, replicating components and subobjects relies on the virtual function AActor::ReplicateSubobjects. For actors with replicated subobjects,…

https://dev.epicgames.com/community/learning/knowledge-base/7y39/unreal-engine-using-the-replicated-subobjects-list

2 Likes

Hello,I follow the document to use the new system,but it’s not work for me,if directly add Replicate Subobject,the engine crashed because of assert: Is Support For Networking.I also try to override UObject derived class’ s function(Is Support For Networking,return true)
Engine stop crash,but UObject not replicate to client.
really thanks

Unreal Engine 5.1 ReplicateSubobjectList Not Working - Programming & Scripting / C++ - Epic Developer Community Forums

Thanks for the explanations.

I’ve got three questions:

  1. GetLifetimeReplicatedProps
    I assume that the usage of GetLifetimeReplicatedProps() did not change with this? So I still can do e.g.

    void AMyActor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& 
    OutLifetimeProps) const
    {
        Super::GetLifetimeReplicatedProps(OutLifetimeProps);
        DOREPLIFETIME_CONDITION(AMyActor, MySubObject, COND_OwnerOnly);
    }
    

    ? Also for actor components (if I don’t use AllowActorComponentToReplicate())?

    Or should I only use the second parameter of AddReplicatedSubObject() to set this? Then I’d have a mixed solution for replicated subobjects and replicated primitives like booleans.

  2. ReplicateSubobjectList()
    Is there an equivalent for that function? It is marked as deprecated, but AddReplicatedSubObject() doesn’t accept a list of objects. Or is iterating the list manually and calling AddReplicatedSubObject() for every list entry the intended way?

  3. Focus on server. Should RemoveReplicatedSubObject() be only called on server or also on clients? Or asking differently: Should I calls this where I called AddReplicatedSubObject()? Since the sub object list can differ from server and client?

Hello, I’m using the COND_NetGroup and FNetConditionGroupManager to replicate subobjects only to some clients.

Now, when I add the players to the same netgroup of the subobject via APlayerController::IncludeInNetConditionGroup all works as it should and the subobject is created and replicated to the client. The problem is that when I remove the player from the netgroup using APlayerController::RemoveFromNetConditionGroup, while the object properties stops from being replicated, the object itself is not destroyed on the client.

There’s some way to let the client know he’s no more part of that netgroup so that I can destroy the object manually or trigger some cleanup code on the client side? Or should I do it manually by storing for example a replicated array of the player netgroups on the client?