Continue a countdown timer between scenes

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

Hey everyone,

I am trying to create a timer to continue to countdown between scenes. I got the timer to work on a scene. But I can’t seem to figure out how to keep it counting down when they switch. I created a singleton. But I still can’t seem to figure it out.

Any ideas? Thank you!!!

:bust_in_silhouette: Reply From: jgodfrey

You can place the Timer itself in the singleton scene. Then, you can start it, stop it, check the remaining time, whaterver - as needed from any scene. And, the running time should live through scene changes. For example, if you create a scene named Global that contains the following scene tree:

Node2D
    Timer

You can reference that timer from any other scene script like:

onready var timer = get_node("/root/Global/Timer")

_ready():
    time.start()

_process(delta):
    print(timer.time_left)

That’ll start the timer and print its remaining time in each frame, but you can do any normal timer things with it from anywhere…

Thank you so much. I have used that method before. I can’t believe I didn’t think of that. But you def saved me. Really appreciate the help!!!

charliemacdmv | 2023-05-07 02:36