0 votes

Suppose whenever I cast a skill, I create a one-shot timer with wait time 1 in script. Then it will stop after 1 second. But will it queue_free itself? I was reading the documentation and it doesn't say anything about what happens to the timer after expiration so I assume it will just be stopped, and remain in my scene. But if that's the case will there be a problem if I create too many timers? What is a good way to clean up all these expired one-shot timers? Thank you.

Godot version latest
in Engine by (12 points)

1 Answer

0 votes

There's few signals you can use on timers. Such as:

func _on_Timer_tree_entered() -> void:
    print("Tree entered")

func _on_Timer_ready() -> void:
    print("Timer ready")

func _on_Timer_timeout() -> void:
    print("Timer done")

func _on_Timer_tree_exiting() -> void:
    print("Tree exiting")

func _on_Timer_tree_exited() -> void:
    print("Tree exited")

Once the queue_free() is executed the timer leaves the scene. You can see this by running your code and clicking on the Remote nodes to view the running nodes.
If you don't free it up, it will hang around.

by (1,963 points)

Yes, thanks for the info! I was thinking about this from a design perspective, and I realized I should really make my skill a scene, and once the timer expires, queue_free() the scene itself.

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.