Adding delta every frame almost never lands exactly on 5.0, so if time == 5.0 never runs. In our Godot 4.7 test it fired 0 times at 30, 60, 75, 144, 165 and 240 fps: the closest value at 60 fps was 4.999999999999988. if int(time) == 5 goes the other way and fires on every frame for a whole second, 60 times at 60 fps. Check time >= 5.0 and set a flag the first time it is true.
The code
Call start() when the food goes on the stove and tick(delta) from _process(). Connect done to your ready effect and burnt to the smoke. take_off() stops it.
extends Node
## Cooking timer that fires once when the food is done, and once when it burns.
## Call start() when the food goes on the heat and tick(delta) every frame.
signal done
signal burnt
@export var cook_time := 5.0 # seconds until done
@export var burn_time := 9.0 # seconds until burnt
var elapsed := -1.0
var _done_sent := false
var _burnt_sent := false
func start() -> void:
elapsed = 0.0
_done_sent = false
_burnt_sent = false
func tick(delta: float) -> void:
if elapsed < 0.0:
return
elapsed += delta
# >= and a flag, never ==: adding up delta almost never lands exactly on 5.0
if not _done_sent and elapsed >= cook_time:
_done_sent = true
done.emit()
if not _burnt_sent and elapsed >= burn_time:
_burnt_sent = true
burnt.emit()
func take_off() -> void:
elapsed = -1.0
What we measured
We added a steady delta for 10 seconds at 6 frame rates and counted how often each check ran. Two runs with the same numbers.
time == 5.0: 0 times at every frame rate. The closest values were 4.999999999999992 at 30 fps, 4.999999999999988 at 60, 5.000000000000007 at 75, 5.000000000000079 at 144, 4.999999999999918 at 165 and 5.000000000000036 at 240.int(time) == 5: 30, 60, 75, 144, 165 and 241 times, every frame of the sixth second. The extra one at 240 fps comes from the same rounding.- The script:
donefired once at every frame rate, on the first frame at or past 5 seconds: 5.0333 s at 30 fps, 5.0167 at 60, 5.0061 at 165 and 5.0000 at 75, 144 and 240.burntfired once too.
Why it happens
delta is a fraction like 1/60 that a float cannot hold exactly, so every addition is off by a tiny amount and the total ends up just above or just below 5.0. At most frame rates no frame lands on 5 seconds anyway. >= catches the first frame past the mark, and the flag stops it from firing again on every frame after that.
What to change
cook_time: seconds until the food is done.burn_time: seconds until it burns. Make it longer thancook_timeso the player has a window to take it off.
Steam that turns to smoke as it burns: steam to black smoke. Timers that should stop during pause: cooldown counting while paused. Seconds left on screen: a countdown that never shows 0 early.
Ready-made kitchen effects: Cooking & Kitchen VFX for Godot 4 has 23 presets in Stylized and Retro PSX looks, including Pot Boil, Pan Sizzle, Burnt Smoke, Pan Fire and a Fire Extinguisher.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Cooking & Kitchen VFX for Godot 4 has 23 ready-made kitchen effects for done and burnt food, including Pot Boil, Pan Sizzle, Burnt Smoke and Pan Fire, in Stylized and Retro PSX looks.
More how-tos for Cooking & Kitchen VFX for Godot 4: Steam that turns to black smoke when the food burns · A countdown that never shows 0 while time is left
More how-tos: Game systems
- Hover a 3D object inside a SubViewport
- A turned building that covers the cells it stands on
- An inventory that never loses an item and never overfills a stack
- A JSON save that loads back exactly what you saved
- Fire that spreads one cell per step, in every direction
- A pooled enemy that comes back as fresh as a new one
- An enemy that stops at the dead player and finds the respawned one
- Poison, burn and bleed that keep ticking when applied again
- XP, qi and gold that keep growing without going negative
- Count slot line wins with wilds in front
- Random directions spread evenly over a sphere or a cone
- Count a lap only when the car really went round
- Make a seed repeat: daily runs, replays and roguelike seeds
- Offline progress that counts the time the game was closed
- A chance roll without the long bad-luck streaks
- Check crafting recipes in any order, with the right counts
- Make HP and mana regen the same at any frame rate
- Damage over time with the right number of ticks
- Spawn enemies where the camera cannot see them
- Keep a chasing horde from stacking into one enemy
- Make the fish bite after the same wait at any frame rate
- Snap buildings to the right grid cell on both sides of the origin
- Pick from a weighted loot table with the right chances
- Level up as many times as the XP covers
- Walk a patrol guard to each point without overshooting
- Remove items from an Array while checking them, without skipping any
- Scatter spikes, roots or trees in a circle without overlaps
- Count and take crafting items from every stack
- Play random sounds and events without obvious repeats
- Pick the growth image so the ripe one shows exactly when the crop can be picked
- Turn a day counter into season, day and year without a day 0
- An enemy that dies once, however many hits land
- A fair shuffle you can replay
- A ghost that drives the lap at real speed
- A vision cone that does not flicker at the edge
- Move a group of units without a pile-up
- A sprinkler that waters a round patch
- A slot reel that always lands forward on the result
- A crowd of NPCs that never emote or bob in step
- A song position that moves on every frame
- Nodes your editor tool adds that stay in the scene