0 votes


How can I set a Node2D or a Control to show behind the root viewport? I have some items that I only want to display if there's nothing shown in the root viewport at that location. I already know to do get_viewport().transparent_bg=true, but for the life of me I can't figure out how to use Node2D's z-indices or Control's show behind or show on top features to get them to display behind the root viewport.

How do skyboxes do it, for example?

in Engine by (56 points)

1 Answer

0 votes

Use Canvas Layers.

Here's a short clean tutorial vid on YouTube.

Godot Tutorial - How To Set CanvasLayer's Layer Using GDScript Code (No Commentary) by user "Making Games And More"


Relevant part from this doc page :

Viewport children will draw by default at layer "0", while a CanvasLayer will draw at any numeric layer. Layers with a greater number will be drawn above those with a smaller number. CanvasLayers also have their own transform and do not depend on the transform of other layers. This allows the UI to be fixed in screen-space while our view on the game world changes.

An example of this is creating a parallax background. This can be done with a CanvasLayer at layer "-1". The screen with the points, life counter and pause button can also be created at layer "1".


by (36 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.