Lifetime
Removes the node after some seconds: back to its pool or destroyed.
component gameplay.Lifetime
On this page
Try it
A node with a lifetime
The bar reads the running Lifetime's Remaining value: it is long above 30 seconds and short below. The node disappears at zero.
Change Seconds from 60 to 8. The bar becomes short and its node disappears after eight game seconds. Reset restores the original node.
Starts the scene; open the example parameters to experiment.
Scene3 nodes
Scriptmain.aes
package demo
// The bar reads the actual runtime Remaining value, not the configured field.
// It disappears with the node when Lifetime reaches zero.
script TimerDisplay {
func Update(dt float) {
remaining := node.Get<Lifetime>().Remaining
if remaining > 30 {
node.Get<SpriteRenderer>().Size = Vec2{6, 1.5}
} else {
node.Get<SpriteRenderer>().Size = Vec2{2, 1.5}
}
}
}
Fields
| Name | Type | Default | Description |
|---|---|---|---|
| Seconds | float | 2 | Seconds the node lives. ≥ 0 |
| Unscaled | bool | false | Counts real time, also while paused or slowed down. |
| Despawn | bool | false | Returns the node to its pool instead of destroying it. |
Runtime state
Values the component has while the game runs. They are not saved with the scene.
| Name | Type | Default | Description |
|---|---|---|---|
| Remaining | float | 0 | Seconds left. |
Related guides
- Lifetime Lifetime removes its node after Seconds of game time, or real time with Unscaled.
- Gameplay kit The gameplay module adds the parts most 2D games rebuild by hand: a character controller, hit points, hitboxes and hurtboxes, kill zones, checkpoints with respawn, pickups and timed removal.