godotengine / godotengine/godot
Timer.time_left using the wrong wait_time
- Dominant language
- C++
- Stars
- 117k
- Forks
- 26.8k
- PR merge metrics
- PR metrics pending
Description
### Tested versions
Reproducible in: v4.5.1.stable.arch_linux
### System information
OS: EndeavourOS
### Issue description
Hi!
So, if you add a Timer node to a scene and set its wait_time in code, time_left will still use the wait_time set in the editor instead of the value you changed it to. However, when printing the wait_time, it will still print the time you set it to in your code.
Pretty confusing when trying to debug why your timer's not working right. Tested the timer and realized that's what's not working. It shouldn't behave like it has two different values for wait_time. The documentation says time_left is based on wait_time, but somehow it's based on the editor's wait_time, while printing gives a different value. My explanation is probably a bit confusing. It's easier to see in the MRP.
Sorry if I'm doing something wrong with the bug report, I haven't made one before.
### Steps to reproduce
Make a new project and add a Timer node. In the editor set the wait_time to 10 seconds. In the _ready() function set it to 100 seconds. Set the timer to autostart. Then print wait_time and time_left in _process. It will print "wait_time: 100 s" "time_left: 10 s"
```
@onready var timer:Timer = $Timer
func _ready() -> void:
timer.wait_time = 100.0
func _physics_process(delta:float) -> void:
print("timer.wait_time: " + str(timer.wait_time) + " s") # 100 s
print("timer.time_left: " + str(timer.time_left) + " s") # 10 s
```
### Minimal reproduction project (MRP)
[timer-test copy.zip](https://github.com/user-attachments/files/23474822/timer-test.copy.zip)
Contributor guide
Research direction
Run the attached minimal reproduction project and verify the Timer node behavior using the shown _ready() and _physics_process() code. Start by tracing the Timer implementation and how wait_time and time_left are updated. Done means changing wait_time in _ready() makes time_left follow the new value rather than the editor value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100