RealDocs

AActor::EndPlay

function Engine Blueprint Since 1.0
#include "GameFramework/Actor.h"
Access: protected Specifiers: virtual

Description

Called when this actor's lifespan ends. Inspect `EndPlayReason` to distinguish between destruction, level streaming, and game end. Use this to clean up timers, delegates, and external references.

Signature

virtual void EndPlay(const EEndPlayReason::Type EndPlayReason)

Parameters

Name Type Description Default
EndPlayReason EEndPlayReason::Type The reason the actor is ending play (destroyed, level transition, game end, etc.).

Return Type

void

Caveats & Gotchas

  • Always call `Super::EndPlay(EndPlayReason)` when overriding.
  • Do not attempt to spawn new actors or access world subsystems that may already be torn down when EndPlayReason is `EEndPlayReason::EndPlayInEditor` or `EEndPlayReason::Quit`.
  • Timer handles are automatically invalidated after EndPlay, but binding delegates to UObjects that are being destroyed can cause crashes — clear them here.

Example

Cleaning up in EndPlay C++
void AMyActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
    Super::EndPlay(EndPlayReason);

    // Invalidate any timers
    GetWorldTimerManager().ClearTimer(MyTimerHandle);

    // Unbind delegates
    OnSomeEvent.RemoveDynamic(this, &AMyActor::HandleEvent);

    UE_LOG(LogTemp, Log, TEXT("EndPlay reason: %d"), (int32)EndPlayReason);
}

Version History

Introduced in: 1.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.