Does a timer node stack with each other and eventually make the game slow?

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

Hi,

I have scripts that uses timers but through GDScript like so:

yield(get_tree().create_timer(time), "timeout")

I don’t quite understand if this script create a timer node in the scene tree and ‘clears’ itself out when the timer is out. Assuming I used this a couple of times in a single scene, will it slowdown my game?

:bust_in_silhouette: Reply From: hilfazer

This code creates SceneTreeTimer which is not a Node but a Reference. It means it will be destroyed once current function completes.

It is possible many of those Timers will be active at the same time if you call your function often and time is comparatively long. For example if you call your code 100 times per second and time equals 2s there will be up to 200 SceneTreeTimers at the same time.

But you don’t need to worry about freeing them.

Thanks for clearing that out. I use them for invincibility timers when the players get hurt.

carbajosa | 2019-01-20 05:59