UBehaviorTreeComponent::AddReferencedObjects
#include "BehaviorTree/BehaviorTreeComponent.h"
Access: public
Specifiers: static
Description
Reports extra UObject references held by the behavior tree instance stack to the garbage collector. Overrides the standard UObject reference-collection hook so that objects reachable only through non-UPROPERTY internal state aren't collected prematurely.
Caveats & Gotchas
- • This is a static callback wired up via UClass::AddReferencedObjects, not a virtual member you override per-instance — you almost never call or override it directly in gameplay code.
- • It exists because the behavior tree instance stack holds node instance memory and object pointers outside of normal UPROPERTY reflection; skipping this hook would let the GC collect nodes still in use.
- • If you subclass UBehaviorTreeComponent and add your own non-UPROPERTY UObject pointers, you must extend this function (or add proper UPROPERTY fields instead) or your objects can be garbage collected while still referenced.
Signature
static AIMODULE_API void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| InThis | UObject* | The object being scanned by the garbage collector, expected to be a UBehaviorTreeComponent. | — |
| Collector | FReferenceCollector& | Collector used to report additional UObject references that aren't UPROPERTY-tracked. | — |
Return Type
void Example
Typical declaration in a subclass C++
class UMyBehaviorTreeComponent : public UBehaviorTreeComponent
{
GENERATED_BODY()
public:
static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector)
{
UMyBehaviorTreeComponent* This = CastChecked<UMyBehaviorTreeComponent>(InThis);
Collector.AddReferencedObject(This->CustomTrackedObject, This);
Super::AddReferencedObjects(InThis, Collector);
}
}; See Also
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?