I want to delete a scene and re-load it. This code would fail later, because the new "CoolScene" has in fact a different name, something like "@NotSuchCoolName@34", and thus it cannot be referenced with $CoolScene once the garbage collector destroys the old scene:
$CoolScene.queue_free()
var cool_node = load("res://pathto/CoolScene.tscn").instance()
add_child(cool_node )
cool_node.set_name("CoolScene")
But if I rename the scene, then it will work:
$CoolScene.set_name("oldCoolScenebyebye")
$oldCoolScenebyebye.queue_free()
var cool_node = load("res://pathto/CoolScene.tscn").instance()
add_child(cool_node)
cool_node.set_name("CoolScene")
$CoolScene.whatever #Works now!
However this looks like awful code to me, main reason being that I need to invent temp names that are unique everytime a scene gets deleted, something that should be done by the garbage collector. Please help me write better code!