In my Godot game, a racer can pick up power ups/weapons which they get to keep for 15 seconds, before they disappear. On my hud, which is in a separate scene (a canvas layer) to where the weapon time is handled, I want a progress bar that shows how much time you have left with the weapon.
I am having trouble doing this since while I could just make a global variable for the time left, set the weapon timer’s time left to it, and then just use set gets to send a signal to set the UI time to the current time, this seems bad. Sending a signal after every second (or even less) just seems inefficient and clunky.
Nothing wrong with sending a signal every second. I assume there will only ever be a handful of powerups in effect at the same time? I doubt it’ll have a noticeable performance impact.
Just as an example of how signals are used in the engine: Every single frame and physics frame, a signal is fired (which you can await if you want to for example spread some calculation over multiple frames).
If you really don’t want to send that many signals, though, you can try only sending a signal when the powerup starts, and then just letting the UI keep track of time on its own. You can use Time.get_ticks_msec() to see how many milliseconds have passed since the game started, and then calculate how much time is left on the powerup based on that.