RealDocs

UActorComponent::EndPlay

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

Description

Called when gameplay ends for this component. Only fires if BeginPlay was previously called (bHasBegunPlay is true). Use this to clean up timers, delegates, and other runtime state.

Caveats & Gotchas

  • Always call Super::EndPlay(EndPlayReason) — the base implementation clears bHasBegunPlay and fires ReceiveEndPlay. Skipping Super leaves bHasBegunPlay set, which can cause BeginPlay to not fire correctly if the component is reused.
  • EndPlayReason distinguishes between actor destruction, level removal, and PIE end — check the reason if your cleanup logic differs (e.g. do not save persistent data when EndPlayReason == EEndPlayReason::EndPlayInEditor).

Signature

ENGINE_API virtual void EndPlay(const EEndPlayReason::Type EndPlayReason)

Parameters

Name Type Description Default
EndPlayReason const EEndPlayReason::Type The reason gameplay is ending for this component (e.g., actor destroyed, level unloaded, PIE ended).

Return Type

void

Example

Cleaning up a timer on EndPlay C++
void UMyComponent::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
    Super::EndPlay(EndPlayReason); // Must call Super
    GetWorld()->GetTimerManager().ClearTimer(MyTimerHandle);
}

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.