Change singleton's script in runtime.

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

Excuse me, I tried to change script for singleton but it doesn’t work. Am I doing it wrong?
some_singleton.set_script(load("res://system/server/command.srv.gd"))
I also tried other combination but still wont work until now. Can I even change singleton’s script in runtime? If not, can I make singleton in runtime?

I have a singleton that will have 2 different script based on if it’s client or server. When the main scene loaded, it will detect if the game is running as client or server then change it’s singleton script. Is that bad practice?

You can’t make so-called singleton at runtime. What you can do is to add a scene as a child of root:

$"/root".add_child( aScene )

It will be accessible where SceneTree is.

hilfazer | 2019-01-06 11:21

ah i see, thank you. hmm, well if I can’t do that, I think I’ll just make a child of a singleton and then reference it manually to all nodes who need it.

pegasusearl | 2019-01-06 14:33