0 votes

Is it possible to change singleton during runtime via code? Or set singleton during runtime?
For example. I have StartMenu scene (My tree look like: [root].[StartMenu]). After pressing start button I want to change scene and use some scripts like they were autoloaded (My new tree: [root].[AutoloadedScript1,AutoloadedScript2,MainScene]).

I ask, because my scripts, which I want to be autoloaded, have some referances to nodes from MainScene node. And when they are loaded from the beginning, there are ofc errors because engine cant find these nodes. Now I know, I shouldnt design Singletons in this way. Just asking if there is a solution or should I redesign all code.

in Engine by (22 points)

1 Answer

0 votes

i would make one master-singleton and in this master-script instanctiate your current scene script

Master.currentScene = StartMenu

when button is pressed

Master.currentScene = AutoloadedScript1

then you can allways access your current scene with

by (4,084 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.