+2 votes

I want my UI/HUD to scale with the viewport and have labels align to various corners of the screen etc.

The root of my UI is a Control node and I have a single label in the bottom right corner. It works well when viewing the UI's separate scene:

Separate scene

However, when I drop that into the main scene of the game this breaks and now thinks the viewport size is 0, 0, sending the label off-screen (I guess it's still adhering to the margin but the rect size is broken).

Broken in main scene

Now, I've seen this question and possibly a few similar ones with same answer but that's unsatisfactory. According to the documentation, a top-level Control should "full rect" to the viewport. Now, even in the Game scene, a Node2D is not a control - "HUD" is still the top-level Control.

This guy was able to do exactly that: https://youtu.be/y1E_y9AIqow?t=1942 - after dropping the UI scene into the game scene, it still worked. Does it mean it's a bug because it worked 3 years ago and doesn't work now?

If it's actually the intended behavior now, how to work around it? I can make the "Game" node into a Control too but that feels hacky.

Godot version 3.3.4
in Engine by (14 points)

1 Answer

0 votes

Have your control as a child of a Node or even better, a CanvasLayer (to control its Z index). Should work!

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 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.