Control nodes in a GridContainer

Godot Version

4.3.stable.mono

Question

How to align properly Control nodes in a GridContainer?

Here’s what the problem looks like:
problem
The marquee is the selected GridContainer (placed inside a Panel and anchored to it).
It has 8 Control nodes as children, set in two columns with the proper separation, so those should fill it entirely.

Here is the structure of the GridContainer:
GC structure

And here is what a ‘recovery_spot’ (the Control nodes) look like:
recovery_spot
recovery_spot_visual

If you look back, you can see that the visible sprite of the recovery_spot Controls (and the invisible ones also) appear centered at their coordinates in the GridContiner. For the life of me, I could not make them offset so that the children appear inside of the confines of the GridContainer.

P.S. The contents of the GridContainer will not change during the game, so using it is questionable and placing the Control nodes on screen manually makes more sense, but I need to know how to do this, in case it’s unavoidable and because I bet I’m missing something basic and I need to know.

I guess there is an issue with anchors or pivots in your scenes, but I honestly have a hard time recreating your issue. Whatever I try, my nodes are aligned properly, unless I deliberately misalign the position of the child nodes. Maybe you can have a look at my setup and you can find any differences to yours?



2 Likes

Thank you!

It worked as desired.

I still don’t know what wentwrong with my previous objects. The only difference I think was that I did not have the hor and ver ‘expand’ flags in the theme overrides constants of the GridContainer, but playing with those in the old setup did not fix the problem.
So I redid everything, making sure I match what is seen on your screenshots and now all is fine!

1 Like