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.

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.

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

Examples

Clear a timer and print a message when the actor ends play Blueprint
Event End Play End Play Reason End Play Reason Clear and Invalidate Timer by Handle Handle Print String In String EndPlay: cleanup done EndPlay: cleanup done My Timer Handle My Timer Handle My Timer Handle
Edit Blueprint graph Clear a timer and print a message when the actor ends play
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
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.