RealDocs

AActor::AddReplicatedSubObject

function Engine Since 5.1
#include "GameFramework/Actor.h"
Access: public

Description

Registers a UObject as a replicated sub-object of this actor so its UPROPERTY fields are automatically replicated. Requires bReplicateUsingRegisteredSubObjectList=true on the actor.

Caveats & Gotchas

  • You must also enable bReplicateUsingRegisteredSubObjectList on the actor (set it to true in the constructor). Without this flag the sub-object list is ignored and the legacy ReplicateSubObjects() path is used instead.
  • The sub-object must be removed from the list with RemoveReplicatedSubObject before it is destroyed on the server. Failing to do so leaves a dangling pointer in the registry.
  • This registers the sub-object directly with the actor, not with a component. For sub-objects owned by a component use AddActorComponentReplicatedSubObject instead.

Signature

ENGINE_API void AddReplicatedSubObject(UObject* SubObject, ELifetimeCondition NetCondition = COND_None)

Parameters

Name Type Description Default
SubObject UObject* The UObject to register for replication as a sub-object of this actor.
NetCondition ELifetimeCondition Optional condition controlling which connections receive this sub-object. Defaults to COND_None (all connections). COND_None

Return Type

void

Example

Register an inventory sub-object C++
AMyActor::AMyActor()
{
    bReplicates = true;
    bReplicateUsingRegisteredSubObjectList = true;
}

void AMyActor::BeginPlay()
{
    Super::BeginPlay();
    if (HasAuthority())
    {
        InventoryData = NewObject<UInventoryData>(this);
        AddReplicatedSubObject(InventoryData);
    }
}

Version History

Introduced in: 5.1

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.