0 votes

Hey hi guys I am making a game in which I want to reload maingame scene after player presses play in menu here I can’t use reloadcurrentscene cause all my game components are child of a node called by the name world and I kept them all (maingame,mainmenu,shop etc.) for some reason and when I reloadcurrentscene 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.

Godot version v3.4.4
in Engine by (29 points)

2 Answers

0 votes

You may want to use AutoLoad https://docs.godotengine.org/en/stable/tutorials/scripting/singletons_autoload.html
And move your persistent data/functionality there.

by (14 points)
edited by

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

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.

+1 vote

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.

by (34 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.