As far as I know, singletons are always placed above the currently loaded scene.
Among other Singletons, I think the order is the same as in the project settings under the Autoload
tab. If your HUD needs to appear above all of the other singleton scripts, then in theory it should just be a matter of changing the order in the Autoload
tab.
If you need your HUD to be above all singleton scripts and the loaded scene, then you may need to use a CanvasLayer
and place all of your HUD elements as children to that. By using a CanvasLayer, you can change the layer
property so that it draws on top of all the elements in the scene.
Other than using a CanvasLayer
, I'm not sure how to place UI elements in a singleton reliably above everything else in the scene.
In theory you could use do something like this so that the singleton is the last child, therefor it will be drawn over everything else, but I have no idea if it would work or not:
var parent_node = get_parent()
parent_node.remove_child(self)
parent_node.add_child(self)
If this works though, you will have call this code shortly after you load any new scenes using get_tree().change_scene
, because every time you change scenes the newly loaded scene is added as the last child of root
.
Hopefully this helps!