UActorComponent::OnComponentDestroyed
#include "Components/ActorComponent.h"
Access: public
Specifiers: virtual
Description
Called just before the component is destroyed. Override to release resources or unbind delegates that the component acquired during its lifetime.
Caveats & Gotchas
- • Check bDestroyingHierarchy before performing expensive operations like detaching children — when it is true, those children are being destroyed anyway and re-parenting is wasted work.
- • Called before the UObject is marked pending kill, so the component's fields are still valid here; unlike BeginDestroy, this is the safe place to clear references on other UObjects.
Signature
ENGINE_API virtual void OnComponentDestroyed(bool bDestroyingHierarchy) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| bDestroyingHierarchy | bool | True when the entire component hierarchy is being torn down (e.g., actor destruction). Allows skipping expensive per-component cleanup that would be redundant when everything is going away. | — |
Return Type
void Example
Cleaning up resources on destruction C++
void UMyComponent::OnComponentDestroyed(bool bDestroyingHierarchy)
{
// Unbind delegates to avoid dangling references
if (AActor* Owner = GetOwner())
{
Owner->OnActorBeginOverlap.RemoveAll(this);
}
Super::OnComponentDestroyed(bDestroyingHierarchy);
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?