0 votes

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

Godot version 3.3.4.stable
in Engine by (20 points)

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 processmode is TIMERPROCESS_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.

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.