How to make a timer even when I reload current scene?

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

I’m creating a boss fight in my game and I’ve set the scene to reload whenever my character dies. I want to timer to keep going even if I do reload _ current _ scene().

How can I do that?

:bust_in_silhouette: Reply From: INeeedHealing

If the timer is in the scene it will always reset it self if the scene is reloaded.
Instead you could save the time that allready passed into a singelton before you reload. This variable than doesnt reset with the scene. After the scene is reloaded you can get the value back and set the timer accordingly.

:bust_in_silhouette: Reply From: vgarg

You don’t need to reload entire scene. You can reload just one node (and its children). This is the best thing about Godot. Each scene is like a node. So you can create a Scene (say Main.tscn) and have a top level Node (say Main). Attach the timer to your Main node. And the rest of the game scene can be child of the Main node, let’s call it ‘Game’. So whenever the character dies, you just reload the ‘Game’ node. And the timer being part of parent node (Main), will continue to tick.

In order to reload a node, I guess you have to call remove_child, and then add_child on the parent node.

Just queue_free() the Game scene. No need to remove_child().

Dlean Jeans | 2019-07-14 12:18