Setting the layer of a Margin Container

Godot Version

4.2.2 Stable

Question

Howdy friends! In my 3D game, I have a text box Margin Container scene that is generated in the level scene through the following code: get_tree().root.add_child(text_box)
This usually creates a textbox that renders in front of everything else in the game whenever the player talks with an npc. The problem is that, when I added a background canvas layer to the game scene along with a canvas world environment and a texture rect for the background, the textboxes now generate behind everything. The canvas layer and it’s children are on layer -5 because I want them to be behind everything, but the textboxes seem to generate on that same layer. Is there a way I can tell them, in the code, to not be on the same layer as the background canvas so that they can stay in the front?

Thank you for your help! I appreciate it.

Is there any specific documentation that addresses this issue?

Usually the scene tree is structured like this:

root (Window)
    - current scene
        - child of the scene root
    - autoloaded scene (scene switcher, event handler, music player, persistent data)

Adding a text box as a direct child of the root is not recommended, so I suggest adding a new canvas layer and the text box to the current scene instead.

root
    - current scene
        - canvas layer
            - text box