Timer timeout inconsistent for small values (but not less than frame time)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Lawand

Hi. I am using a timer and setting the timeout value to small values (I tested in the 20-50 msec range, so timeout values of 0.02-0.05) and the timeout function is being called at inconsistent intervals, for example I tried logging as follow:

var last_ms = 0

func _on_Timer_timeout():
  print("timeout: ", OS.get_system_time_msecs() - last_ms)
  last_ms = OS.get_system_time_msecs()

and the output, when setting a timeout of 0.04:

timeout: 1638228320954
timeout: 33
timeout: 33
timeout: 50
timeout: 34
timeout: 33
timeout: 50
timeout: 33
timeout: 50
timeout: 34
timeout: 33

How can I figure out why the timeout interval is inconsistent? Thanks in advance

Note from the documentation:

The wait time in seconds.

Note: Timers can only emit once per rendered frame at most (or once per physics frame if process_mode is TIMER_PROCESS_PHYSICS). This means very low wait times (lower than 0.05 seconds) will behave in significantly different ways depending on the rendered framerate. For very low wait times, it is recommended to use a process loop in a script instead of using a Timer node.

spaceyjase | 2021-11-30 10:01

Thanks, that was very helpful. Maybe you wanna add that as an answer so that I would accept it? It doesn’t technically achieve what I was after, but now I see it’s not possible to get reliable timers at small timeouts anyway

Lawand | 2021-11-30 23:46