UActorComponent::DestroyComponent
#include "Components/ActorComponent.h"
Access: public
Specifiers: virtual
Description
Unregisters the component, removes it from its owner Actor's Components array, and marks it for pending kill. Use this to permanently remove a runtime-created component.
Caveats & Gotchas
- • Do not call this from inside the component's own tick or event handlers — defer it to the next frame or use K2_DestroyComponent from Blueprint, as destroying mid-execution can leave dangling references.
- • bPromoteChildren=true re-parents attached child scene components; if you omit it and the component has children, those children will be destroyed along with it.
Signature
ENGINE_API virtual void DestroyComponent(bool bPromoteChildren = false) Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| bPromoteChildren | bool | If true, child components attached to this component are re-parented to this component's parent rather than being destroyed with it. | false |
Return Type
void Example
Destroying a dynamically created component C++
if (IsValid(SpawnedComponent))
{
SpawnedComponent->DestroyComponent();
SpawnedComponent = nullptr;
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?