AActor::SetLifeSpan
#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
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);
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?