How to reload a particular scene in my game

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

Hey hi guys I am making a game in which I want to reload main_game scene after player presses play in menu here I can’t use reload_current_scene cause all my game components are child of a node called by the name world and I kept them all (main_game,main_menu,shop etc.) for some reason and when I reload_current_scene it reloads full game namely world.
Can anyone please help me and tell me what can I do to reload my game scene every time I press play in main_menu.

:bust_in_silhouette: Reply From: romanpapush

You may want to use AutoLoad Singletons (Autoload) — Godot Engine (stable) documentation in English
And move your persistent data/functionality there.

Bro there is nothing like auto load in Godot expect singleton and we can’t use them them for reloading a scene

Harshitsoam | 2022-07-24 13:13

It’s literally in the first paragraph of the link I provided:

Singletons (AutoLoad):
Godot’s scene system, while powerful and flexible, has a drawback: there is no method for storing information (e.g. a player’s score or inventory) that is needed by more than one scene.

Using Singletons, you can create objects that:

  • Are always loaded, no matter which scene is currently running.
  • Can store global variables such as player information.
  • Can handle switching scenes and between-scene transitions.

You don’t use singleton to reload a scene, you use it to store persistent data.
OP already knows how to reload a scene, and was asking how would he reload his game while maintaining some portion of his nodes/data between those reloads.

Cheers.

romanpapush | 2022-07-24 13:49

:bust_in_silhouette: Reply From: godot_bugmenot

Maybe you can try to:

  • orphan child nodes that you wish to keep
  • temporarily attach them to an another temporary parent
  • reload the whole scene (keeping the temporary parent from being reloaded)
  • reattach your children and move on.

When i have had a similar problem like yours i went with a “overworld” solution - the world is inside of a master node and so it can be easily reloaded, while important children are reattached to a temporary node.