RealDocs

UAnimInstance::AddReferencedObjects

function Engine Since 4.0
#include "Animation/AnimInstance.h"
Access: public Specifiers: static

Description

Reports non-UPROPERTY UObject references held by this animation instance to the garbage collector. Ensures that objects referenced by animation nodes (montages, sequences, blend spaces) are not prematurely collected.

Caveats & Gotchas

  • This is called by the garbage collector on any thread — do not access game state, tick counters, or anything that is not thread-safe from within this function or an override.
  • If you add custom non-UPROPERTY UObject references in an AnimInstance subclass, you must override this function and report them via Collector.AddReferencedObject, or the GC may collect them while still in use.

Signature

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

Parameters

Name Type Description Default
InThis UObject* The UAnimInstance object being processed by the garbage collector.
Collector FReferenceCollector& The reference collector to report referenced objects to.

Return Type

void

Example

Override to report custom references C++
void UMyAnimInstance::AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector)
{
    UMyAnimInstance* This = CastChecked<UMyAnimInstance>(InThis);
    Collector.AddReferencedObject(This->CachedMontage);
    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.