RealDocs

AActor::OnSubobjectDestroyFromReplication

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

Description

Called on the client actor just before the replication system destroys a subobject that no longer exists on the server. Override to clean up any cached references before the object is invalidated.

Caveats & Gotchas

  • Subobject is still valid during this call but will be destroyed immediately after — do not store the pointer.
  • This is the correct place to remove entries from arrays or maps that hold references to the subobject; failing to do so leaves dangling pointers.
  • Only used with the legacy ReplicateSubobjects path; the Registered SubObject List handles cleanup differently.

Signature

ENGINE_API virtual void OnSubobjectDestroyFromReplication(UObject *Subobject)

Parameters

Name Type Description Default
Subobject UObject * The subobject that is about to be destroyed on the client due to server-side destruction.

Return Type

void

Example

Remove destroyed item from cached array C++
void AMyActor::OnSubobjectDestroyFromReplication(UObject* Subobject)
{
    Super::OnSubobjectDestroyFromReplication(Subobject);
    if (UInventoryItem* Item = Cast<UInventoryItem>(Subobject))
    {
        ReplicatedItems.Remove(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.