• Godot HelpGUI
  • Setting a node to always appear on top (and be interactable) without CanvasLayer

All recommendations I've seen thus far point at using CanvasLayer to place a node above every other one. This works ordinarily but for this project I'm working on, the node is instanced in an hboxcontainer and this does not work well with the CanvasLayer, as the CanvasLayer does not give the hboxcontainer control of it's positioning as intended. Since the hboxcontainer is central to the way things have been laid out, how else can the node he set to appear (and be interactable, it's a button) at the top level, no matter it's position on the scene tree (yes I understand that the lowest node on the scene tree is the one at the top level, but with what I'm doing, it's not possible to have the desired node at the bottom of the scene tree all the time.

Welcome to the forums @DADA_universe!

I have not tried it myself, but you may be able to change the Z-index and draw order of the control node, which should allow you to control how its drawn. Something like this should work when attached to the node, though I have not tested it:

var canvas_rid = get_canvas_item()
# You may need to adjust these values
VisualServer.canvas_item_set_draw_index(100)
VisualServer.canvas_item_set_z_index(100)

Here's the documentation for the various functions: get_canvas_item canvas_item_set_draw_index * canvas_item_set_z_index

Thanks @TwistedTwigleg, I never knew of the VisualServer. Indeed I was able to get the node drawn to the front (the node is a pop up with a grid of buttons by the way) some of the buttons work however, while some, obviously still masked by other nodes in the scene are not working. I raised the index to 1,000 just to be sure and it made no difference.

Great! I'm glad that worked visually. I'm guessing that the buttons that are not working are because even if they visually look like they are on top of everything, Godot processes their input detection in the order they appear visually prior to using the VisualServer. I'm not sure how to work around that though, but maybe there is another server and/or setting that can adjust the input order.

2 years later