RealDocs

APawn::DetachFromControllerPendingDestroy

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

Description

Safely unpossesses the pawn from its controller in preparation for imminent destruction. Unlike calling Controller->UnPossess() directly, this method handles edge cases where the controller may itself be pending destruction.

Caveats & Gotchas

  • Call this instead of raw controller manipulation when the pawn is about to be destroyed (e.g. from a death function). Calling UnPossess() directly on a pawn that is already mid-destruction sequence can trigger controller callbacks on a partially destroyed pawn.
  • After this call the pawn's Controller pointer is null — any code running after this that dereferences Controller without a null check will crash.

Signature

virtual void DetachFromControllerPendingDestroy()

Return Type

void

Example

Detach controller during death sequence C++
void AMyPawn::Die()
{
	// Prevent the controller from re-possessing or continuing to send input
	DetachFromControllerPendingDestroy();

	// Start ragdoll, play death animation, then queue destroy
	GetMesh()->SetSimulatePhysics(true);
	SetLifeSpan(5.f);
}

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.