← Pixel Dreamer Studio

Keep a buff aura on until the last buff really runs out

Store when each buff ends, hide the aura only when none is left, and never let a pickup shorten a buff.

Two buffs at once is where aura code usually breaks. In our Godot 4.7 test: a 10 second fire buff at 0 s, a 3 second speed buff at 2 s, and the fire buff picked up again for 2 seconds at 4 s, so the last buff really ends at 10 s. A timer per pickup that hides the aura turned it off at 5 s. One Timer restarted on every pickup turned it off at 6 s. One end time per buff kept the aura on until 10.00 s.

The code

Add the script as a child of the character, connect aura_changed to show or hide your aura (or start and stop its particles), and call add_buff(name, seconds) on every pickup. The same buff picked up again is extended when the new time is longer, and never cut short.

extends Node
## Keeps an aura on while at least one buff is still running, even when buffs
## overlap or the same buff is picked up again. Connect aura_changed to your effect.

signal aura_changed(on: bool)

var _now := 0.0
var _ends := {}  # buff name -> time it runs out
var _on := false


func add_buff(buff_name: String, seconds: float) -> void:
	_ends[buff_name] = maxf(_ends.get(buff_name, 0.0), _now + seconds)  # again = longer, never shorter
	_update()


func _process(delta: float) -> void:
	_now += delta
	for k in _ends.keys():
		if _ends[k] <= _now:
			_ends.erase(k)
	_update()


func _update() -> void:
	var on := not _ends.is_empty()
	if on != _on:
		_on = on
		aura_changed.emit(on)

What we measured

The pickups above at 60 fps for 12 s. Two runs with the same numbers.

Why it happens

Each of those timers only knows its own pickup. Hiding the aura has to ask whether any buff is still running, and a second pickup must not swap a longer time for a shorter one.

What to change

Aura particles around a character: magic aura particles. Timers and pausing: a cooldown that keeps counting while paused.

Auras that follow the animation: Character Aura Kit for Godot 4 emits auras from a rigged character's own skin and follows the animation: power-up, fire, ice, poison, lightning, dissolve.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Character Aura Kit for Godot 4 emits auras from a rigged character's own skin and follows the animation: power-up, fire, ice, poison, lightning, dissolve.

More how-tos for Character Aura Kit for Godot 4: An aura that comes back when the buff comes back

More how-tos: Auras, rings, beams and weather