RealDocs

AActor::SetLifeSpan

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

Description

Schedules this actor to be automatically destroyed after the given number of seconds. Passing 0 cancels any existing timer so the actor lives indefinitely.

Caveats & Gotchas

  • The timer is affected by the actor's time dilation — a lifespan set to 5s on an actor with 0.5x dilation will take 10 real seconds to expire.
  • Calling this multiple times resets the timer to the new value; the old countdown is discarded. If you want the first call to 'stick', guard it with a check against `GetLifeSpan() > 0`.
  • Must be called after `BeginPlay` — setting a lifespan in the constructor or in `OnConstruction` may not produce a valid timer handle in all contexts.

Signature

ENGINE_API virtual void SetLifeSpan( float InLifespan );

Parameters

Name Type Description Default
InLifespan float Time in seconds until the actor is destroyed. Pass 0 to cancel an existing lifespan timer.

Return Type

void

Examples

Auto-destroy a projectile 5 seconds after spawning Blueprint
Event BeginPlay Set Life Span Target is Actor Target In Lifespan 5.0 5.0 Print String In String Lifespan set! Lifespan set!
Edit Blueprint graph Auto-destroy a projectile 5 seconds after spawning
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
Self-destruct a projectile after 5 seconds C++
void AMyProjectile::BeginPlay()
{
	Super::BeginPlay();
	// Destroy if it hasn't hit anything within 5 seconds
	SetLifeSpan(5.0f);
}

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.