RealDocs

AActor::OnSubobjectCreatedFromReplication

function Engine Since 4.0
#include "GameFramework/Actor.h"
Access: public Specifiers: virtual

Description

Called on the client actor when the replication system dynamically creates a new subobject that was spawned on the server. Override to cache or initialize the newly replicated subobject.

Caveats & Gotchas

  • Called before the subobject's replicated properties are applied — do not read replicated data from NewSubobject inside this callback.
  • Only fires when using the legacy ReplicateSubobjects path. With the Registered SubObject List approach, use component OnRep callbacks or AddReplicatedSubObject instead.
  • NewSubobject may already exist in the actor's component list if it was created as an ActorComponent — always check IsValid before caching.

Signature

ENGINE_API virtual void OnSubobjectCreatedFromReplication(UObject *NewSubobject)

Parameters

Name Type Description Default
NewSubobject UObject * The subobject that was dynamically created by the replication system on this client.

Return Type

void

Example

Cache a dynamically created inventory item subobject C++
void AMyActor::OnSubobjectCreatedFromReplication(UObject* NewSubobject)
{
    Super::OnSubobjectCreatedFromReplication(NewSubobject);
    if (UInventoryItem* Item = Cast<UInventoryItem>(NewSubobject))
    {
        ReplicatedItems.Add(Item);
    }
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.