How can I get a control node to fill the viewport?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By YangTegap

I have an HBoxContainer that I want to fill the width of the screen, and stretch / shrink with the screen when resized.

Here is how I currently have the tree set up:

Control > Panel > HBoxContainer

The HBoxContainer has size flags set to expand horizontally to fill the panel, and both the panel AND the Control are set to “full rect,” and they visually fill the viewport in the editor. However, when I run the scene, my debugging script tells me that the width of both the control and panel nodes are at 0 (which doesn’t make sense because I can visually see the panel fills the screen still).

What am I doing wrong?

:bust_in_silhouette: Reply From: RaebaldKashban

I attempted to replicate your set-up. Control as root of scene, Panel as child of Control, and HBoxContainer as child of Panel. Both Control and Panel are sect to “full rect” and “HBoxContainer” is set to “expand horizontal.”

Visually, the panel occupies the entire viewport (as expected) and resizes when I resize the window. As far as I can tell, you observe that behavior too.

However, when I sample the rect_size of Control and Panel frame by frame, it gives me expected results (starts at the window size, then changes as I resize the window). I’m not sure what the issue is in your case–what property are you checking to determine the width of the window?

EDIT: I should note that I’m running on Godot 3.4.4, so that may make a difference. I don’t know.

The issue seems to have fixed itself…

I had a script set up on the HBoxContainer that included this function:

func _input(event):
	if event.is_action_pressed("debug"):

Previously, the script would only return a 0, even though that didn’t make sense visually. Accordingly, my other scripts that were affected by the container size wouldn’t work properly.

However, it’s working as expected now, I’m not sure what I changed or if this was just a glitch…

YangTegap | 2022-04-09 18:20