godotengine / godotengine/godot
Timer emits timeout sooner than it should when initialized together with the scene
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Reproducible in: v4.2.stable.official.46dc27791, v4.2.1.stable.official.b09f793f5, v4.2.2.stable.official.15073afe3
### System information
Godot v4.2.1.stable - Windows 10.0.19045 - Vulkan (Mobile) - dedicated AMD Radeon RX 6650 XT (Advanced Micro Devices, Inc.; 31.0.22011.4008) - 13th Gen Intel(R) Core(TM) i5-13400F (16 Threads)
### Issue description
If a timer is initialized together with the scene it emits timeout for the first time sooner than it should.
For example, when I run the project with the script below (Steps to reproduce) I get
```
1723225685.736
1723225686.681
1723225687.681
1723225688.680
1723225689.681
1723225690.681
```
In this case the first timeout signal was emitted 55 milliseconds sooner than expected, and after that the consecutive times remain stable with errors of at most one or two milliseconds.
I have tested with different hardware/wait_times and have gotten discrepancies ranging from 40 up to 72 milliseconds in the first timeout.
### Steps to reproduce
Create a Timer node with autostart = true (or started in _ready, doesn't matter) with the following script:
```
extends Timer
func _ready():
timeout.connect(_on_timeout)
print(Time.get_unix_time_from_system())
func _on_timeout():
print(Time.get_unix_time_from_system())
```
### Minimal reproduction project (MRP)
[test_bug_timer.zip](https://github.com/user-attachments/files/16565193/test_bug_timer.zip)
Contributor guide
Research direction
Start by running the attached minimal reproduction project and checking the Timer node's autostart and _ready behavior around scene initialization. Trace the first timeout relative to the configured wait time, then compare it with subsequent timeout signals. Done means the initial timeout observes the full wait time while later signals remain stable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, godot
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100