RealDocs

APawn::EndPlay

function Engine Since 4.0
#include "GameFramework/Pawn.h"
Access: public Specifiers: virtualoverride

Description

Called when the pawn is removed from the world or when the game ends. Use EndPlayReason to distinguish between destruction, level transitions, and editor-specific teardowns.

Caveats & Gotchas

  • Always call Super::EndPlay(EndPlayReason) to ensure the pawn properly unpossesses and cleans up its controller reference. Skipping this can leave the controller pointing to a destroyed pawn.
  • EEndPlayReason::RemovedFromWorld fires when the level containing the pawn is unloaded during level streaming — this is distinct from the actor being explicitly destroyed. Handle both cases if your cleanup logic matters.

Signature

virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;

Parameters

Name Type Description Default
EndPlayReason EEndPlayReason::Type The reason EndPlay was triggered (destroyed, level transition, PIE end, etc.).

Return Type

void

Example

Clean up resources on end play C++
void AMyPawn::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
	// Release any handles or timers before super cleans up
	GetWorldTimerManager().ClearAllTimersForObject(this);
	Super::EndPlay(EndPlayReason); // Always call super
}

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.