← Pixel Dreamer Studio

A cooldown that waits while the game is paused

Count the time left down with delta in _process, not against the system clock.

Keep the seconds left in a variable and subtract delta in _process(). A paused scene tree does not run it, and delta follows Engine.time_scale. A cooldown that compares Time.get_ticks_msec() with the moment it is ready keeps counting through a pause: in our Godot 4.7 test a 3-second cooldown had 2 s left after 1 s of play, and 0.00 to 0.11 s left after a 2-second pause. The script still had 1.99 s left.

The code

Add one of these per ability, for example as a child of the player named FireballCooldown. Call use() when the player presses the button: it returns false while the ability is cooling down, so cast only when it returns true. left is the time remaining for a cooldown bar, and ready_again fires when it is done.

extends Node
## An ability cooldown that waits while the game is paused and runs slower in slow motion.
## Call use() when the player casts: it returns false while the ability is still cooling down.

signal ready_again

@export var seconds := 3.0

var left := 0.0


func use() -> bool:
	if left > 0.0:
		return false
	left = seconds
	return true


func _process(delta: float) -> void:
	if left <= 0.0:
		return
	left -= delta  # a paused tree does not run this, and delta is scaled by Engine.time_scale
	if left <= 0.0:
		left = 0.0
		ready_again.emit()

What we measured

A 3-second cooldown, used at the start. Two runs gave the same results except the clock-based one, which moved by up to 0.13 s between runs.

Why the system clock is the wrong clock

Time.get_ticks_msec() counts real milliseconds since the game started, whatever the game is doing. A pause menu, a dialogue that pauses the tree, or slow motion all keep that clock running, so a player can open the menu and come back with every ability ready. _process() only runs while the node is not paused, and its delta is game time.

What to change

Slow motion on a big hit: hit stop with time_scale.

A whole spell system: Spell Casting Kit for Godot 4 has cast, charge and channel spells with mana and cooldowns, 4 aiming modes, AoE, elements, status effects such as burn, slow, poison and freeze, knockback, a skill bar with a cast bar, and a demo arena with 9 spells. Its caster counts cooldowns with delta the same way.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Spell Casting Kit for Godot 4 is a whole spell system for Godot 4: cast, charge and channel spells with mana, cooldowns, aiming modes, elements and status effects.

More how-tos for Spell Casting Kit for Godot 4: Aim a spell at the mouse on a 3D floor · Make HP and mana regen the same at any frame rate

More how-tos: Game feel