The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hello. From my understanding, Control nodes should always be in front of all other nodes. I created some Control nodes to make UI, but they all appear behind the 2D nodes in my scene and have no Z Index values. Some help?

in Engine by (33 points)

Can you post a picture of your node structure?

2 Answers

+1 vote

You can have control nodes be the child of a CanvasLayer node if you want them to behave like UI and always in front. Official docs on Canvas Layer for more information.

by (64 points)
0 votes

Control nodes don't always get drawn in front of other nodes. They still follow the scene tree, by that I mean the nodes that are lower in the scene tree get drawn on top of the other nodes, doesn't matter if they're Controls or Node2Ds.


The easiest (and IMO the best way) of fixing UI depth issues is to add a CanvasLayer node to the scene and name it GuiLayer or whatever you want. Then just add your control nodes to that layer.

From the docs:

CanvasItem nodes [AKA all Node2D and Control nodes] that are direct or indirect children of a CanvasLayer will be drawn in that layer. The layer [property] is a numeric index that defines the draw order. The default 2D scene renders with index 0, so a CanvasLayer with index -1 will be drawn below, and one with index 1 will be drawn above. This is very useful for HUDs (in layer 1+ or above), or backgrounds (in layer -1 or below).

by (182 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.