RealDocs

UActorComponent::DestroyComponent

function Engine Blueprint Since 4.0
#include "Components/ActorComponent.h"
Access: public Specifiers: virtual

Description

Unregisters and destroys this component. For components created dynamically at runtime, call this to remove and clean up the component. Automatically detaches from the owner actor.

Signature

virtual void DestroyComponent(bool bPromoteChildren = false)

Parameters

Name Type Description Default
bPromoteChildren bool For scene components: if true, reattach child components to this component's parent before destruction. false

Return Type

void

Caveats & Gotchas

  • Components created with CreateDefaultSubobject() in the constructor should not be destroyed this way — destroying them can corrupt the actor. Only destroy dynamically created components.
  • After calling DestroyComponent(), the component pointer becomes invalid.

Example

Destroying a dynamically added component C++
UDecalComponent* Decal = NewObject<UDecalComponent>(this);
Decal->RegisterComponent();
// ... later ...
Decal->DestroyComponent(); // Clean up

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.