+2 votes

Learning game UI, I noticed that some examples use CanvasLayer node as the UI container but some other examples use Control node for the same purpose.

With a little bit of Unity experience, I remember Unity uses the Canvas component which stretches to the entire viewport for UI and it always displays on top of everything. Is CanvasLayer node of Godot is similar to the Canvas component of Unity?

I wonder why some tutorials use Control node as the UI container instead of CanvasLayer node. I noticed that UI under Control node does not always display on top of all contents.
I saw tutorials that use CanvasLayer node for HUD (hp, mp, score, etc...), but others use Control node for start menus (Start, Option, Quit, etc...). is it a common practice in Godot? Is there any reason or use-case to use Control node instead of CanvasLayer node?

in Engine by (25 points)

1 Answer

+1 vote

The point of the CanvasLayer node is to separate your 2D nodes into different rendering layers. You may not have a need for it in your game now, but it's good practice to place your UI under a CanvasLayer. It allows you, for instance, to specify the layer order (which layer on top of which), and move layers independantly (ex: you have a parallax background on one of your CanvasLayer nodes and you move it by translating the whole layer, or you have a pause menu which "slides down" from the top of the screen when you press pause). https://docs.godotengine.org/en/stable/tutorials/2d/canvas_layers.html#canvaslayers

by (1,100 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 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 webmaster@godotengine.org with your username.