RealDocs

AActor::AddReferencedObjects

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

Description

Static GC hook that lets actors report object references held in non-UPROPERTY storage, ensuring the garbage collector does not prematurely collect those objects.

Caveats & Gotchas

  • Only needed when you store UObject pointers in raw C++ containers or non-UPROPERTY fields — any pointer declared with UPROPERTY is tracked automatically.
  • Always call the parent class implementation (Super::AddReferencedObjects) before adding your own references; omitting this can cause GC failures in base-class bookkeeping.
  • This function is called on the game thread during GC marking; it must not trigger object creation, async loads, or any code that could cause re-entrant GC.

Signature

static ENGINE_API void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);

Parameters

Name Type Description Default
InThis UObject* The actor instance whose additional references should be reported.
Collector FReferenceCollector& The reference collector used by the GC to track object references.

Return Type

void

Example

Report a raw UObject pointer to the GC C++
void AMyActor::AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector)
{
	AMyActor* This = CastChecked<AMyActor>(InThis);
	Collector.AddReferencedObject(This->RawCachedObject);
	Super::AddReferencedObjects(InThis, Collector);
}

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.