This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I'm trying to make in-game GUI that anchor to the game window and adapt to the may different window sizes. My current setup looks like this:
enter image description here
I've also set stretch mode to canvas_items, and aspect to expand in project settings
I've added TextureRect with Full Rect anchor preset set for demonstration purpose. What I want to do is to make sure that TextureRect will always be stretched, and fill the whole window, which works correctly if I don't have any Camera2D nodes on the scene.
enter image description here
Unfortunately, when I try to move the camera, TextureRect will stay on its world position like this:
enter image description here
What can I do to make sure that TextureRect will always follow the camera in this setup?

Godot version 4.0.3.rc.custom_build [4762303f1]
in Engine by (16 points)

I don't understand what the problem is, and when i try to recreate your scene tree i get the desired results.

The problem occurs when I try to move around camera2d object. I'm using this camera to center it on the middle of the generated map. What I want is to make sure that the UI (or TextureRect in this example) will always follow the camera, and will always be anchored and stretched to the corners of the window. What happens is that UI will stay on the same position in the world space. Comparing this to the Unity UI: I want to achieve the same effect as if I have Canvas with Render Mode set to Screen Space - Overlay, but right now it behaves like it's set to World Space.

It does this because your canvas layer is a child of the camera. If the CanvasLayer is a sibling rather than a child, it should always scale to the screen size independent of camera.

That wasn't the case - it happend either when CanvasLayer was a child of the camera or not.

1 Answer

0 votes

I found the source of the problem - for some reason I had Follow Viewport enabled on CanvasLayer. After switching this off, everything works as intended.

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