Efficiency of using Timer vs delta

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By hassny
:warning: Old Version Published before Godot 3 was released.

I’ve seen some tutorials which use a variable which they increment from _process(delta): to get the time elapsed. I’m just wondering are there any drawbacks when using this method as opposed to an actual timer? How does it compare in terms of processing efficiency?

Real world efficiency between the two is negligible and would depend on how the timer is specifically being used. I personally tend to use Timer nodes with the timeout signal connected because it keeps all the timing code separate from the rest of the script.

literalcitrus | 2018-01-11 04:58

For me, it all boils down to how many steps are involved with implementing a timer. With code it’s a 3-5 step process whereas with the timer node, there are more steps involved. I rarely use timer nodes as a result. So in the end, it’s a matter of preference rather than processing efficiency.

gonzo191 | 2018-01-11 12:03

Using a Timer node in code is fairly painless, you don’t have to create it in the editor to use it.

var timer = Timer.new()
timer.connect("timeout", self, "some_func")
timer.set_wait_time(10)
timer.start()

In terms of pure lines of code it’s comparable to creating timer and time limit vars, incrementing in _process() and checking the value every time. The main point of preference for me is separating the timeout callback function from rest of the code, but there are times where having it inside process can be beneficial.

literalcitrus | 2018-01-11 12:12

If timer is needed in a lot of objects is better to use delta. Timer node handles more things that a simple incremental variable and populate the scene-tree… Is other node. But if you can connect the signal of timer to several nodes, maybe any computation is freed… Trial and error!

807 | 2018-01-15 02:00