AActor::GetLifeSpan
#include "GameFramework/Actor.h"
Access: public
Specifiers: virtualUFUNCTIONBlueprintCallableENGINE_API
Description
Returns the remaining lifespan of this actor in seconds. Returns 0 if the actor has no lifespan timer set (i.e., it lives indefinitely).
Caveats & Gotchas
- • A return value of 0 is ambiguous — it means either no timer is set, or the timer expired this frame just before the call. Do not rely on this to detect imminent destruction; bind to `OnEndPlay` instead.
- • The returned value counts down in dilated time (accounting for `CustomTimeDilation` and world dilation), consistent with how `SetLifeSpan` sets the timer.
Signature
ENGINE_API virtual float GetLifeSpan() const; Return Type
float Examples
Print a warning when the actor's lifespan drops below 3 seconds
Blueprint
Warn when a buff is about to expire C++
void AMyBuffActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
const float Remaining = GetLifeSpan();
if (Remaining > 0.f && Remaining < 3.f)
{
// Flash UI warning
OnExpiryWarning.Broadcast(Remaining);
}
} See Also
Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?