Lifetime Timer
Type: GeneralFrees its parent after a set number of seconds. Drop it on bullets, effects and pickups so they clean up after themselves.
Setup
- Save the script as lifetime_timer.gd.
- Add a Node as a child of the scene that should disappear and attach the script.
- Set Seconds in the Inspector.
Code
GDScript
class_name LifetimeTimer
extends Node
## Frees its parent after a set time. Useful for bullets, effects and pickups.
@export var seconds: float = 2.0
var _time_left: float
func _ready() -> void:
_time_left = seconds
func _process(delta: float) -> void:
_time_left -= delta
if _time_left <= 0.0:
get_parent().queue_free()