0 votes

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?

in Engine by (14 points)

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.

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.

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")

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.

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!

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.