Resizing window hides contents

I’m trying to figure out if this is a bug in Goodot, or a mistake on my part. Whenever I resize the window, it sets the size correctly, but it visually deletes all of its contents, showing an empty window. It doesn’t hide() its contents; it just isn’t rendering.

Here’s the code I’m using. It’s happening during a sort_children signal, if that matters.

# Toplevel UI container (UIMain)
func _ready():
	mainContainer.connect("sort_children", onSortMainContainerChildren)

func onSortMainContainerChildren():
	mainContainer.reset_size()
	reset_size()
	get_window().size = size

This signal-handler gets called 3 times in a row on start up, and during the first go-through, it visually deletes its contents when resizing the window.

Also, here’s my scene tree, for reference.
sceneTreeForQuestion

And my version: Godot Engine v4.2.1.stable.official.b09f793f5 on Linux.

I’ve tried calling queue_redraw() or calling get_window().hide() and show() or calling self.hide() and show(). None of these change the behavior. Is there something else I should try?

My ultimate goal is to dynamically resize my UI (and the window) to the size of its current contents. In other words, I want to expand the window when a new control is added or shown on the main container, and to contract it when a control is hidden.

Resizing the UI node is working great, but the window isn’t cooperating!

I figured out the issue, and hopefully this will help someone else. Here are some important things to get out of the way:

  • Firstly, in my simple scene above, the viewport and the window are the same object. The viewport does not live under the window, as I had previously assumed. So, get_viewport() and get_window() return the same /root node and ignoring the viewport as I did above was not the source of my bug.
  • Secondly, in my project settings, I have the stretch settings disabled, which greatly simplifies things for my use case. If you need to support Multiple Resolutions this technique will be harder. I think you just have to scale the UIMain size correctly before applying it to the viewport, but I’m not sure.

Now, here’s the rub: whenever you change the viewport size, it “helpfully” re-positions all of your nodes. This is true whether you change the viewport size in the project settings in the editor, or if you do it with GScript code.

By looking at the “remote” scene tree, I was able to catch this happening after the resize took place. Take a look at the final position of my UIMain node:

bugUIMainRepositionedWhenResizing

As you can see, its Y position has been reset to -137, and its Y size is only 132, so that means it is 5 pixels shy of showing up on the screen at all. So, the best workaround is just to reset the position of the UIMain node after setting the window size.

Based on how confusing and unintuitive this is, I still think it’s a bug. :confounded: :weary:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.