Panel is scaled weirdly first time it becomes visible

Godot Version

4.6

Question

I’ve got a panel I want to pop up when the player hovers over certain text, but if I start the scene with the panel invisible and show it when the text is hovered over, then the first time it shows the scale is all off. The first picture is the first showing, the second is what all subsequent showings look like.

It may be because your update_panel_size is run before VBoxContainer is done checking it’s minimum size. Sometimes it takes couple of iterations to figure that out, especially the first time you enable it. I don’t know if this is technically true but this has been my experience so far, and the conclusion I got. So take it with a pinch of salt.

Try to use PanelContainer instead of Panel. And just set a custiom minimum size for the PanelConatiner. You should not have to run update_panel_size function anymore. PanelContainer size will be decided automatically.

Another solution would be connecting your update_panel_size function to the VBoxContainer’s resized signal, instead of calling it in your update function. So it would automatically update the size of the panel every time VBoxContainer size is updated. But I still recommend the first solution I wrote above.

1 Like