As part of working out a modding framework for a game, I'm trying to replace an auto-loaded singleton with a different object instance at runtime (when a mod is loaded).
According to https://godotengine.org/qa/95097/engine-has_singleton-engine-get_singleton-behaving-expected?show=95163#a95163 , singletons are nodes on the
/root node, so I tried replacing e.g.
SomeSingleton as follows:
var tmpResource = ResourceLoader.load("res://my-mod/SomeSingleton.gd", "", true)
var inst = tmpResource.new()
inst.name = 'SomeSingleton'
However, this does not affect the game's code which refers to
SomeSingleton directly - it still accesses the original instance.
I tried adding
ResourceLoader.load("res://path/to/SomethingThatUsesSomeSingleton.gd", "", true)
in the subclass's
_enter_tree to reload a game code file, hoping that would make it use the new
$"/root/SomeSingleton" but that did not have any effect.