Godot Version
v4.2.2.stable.official [15073afe3]
Question
I am trying to make a hotbar and an inventory. In the scene where the hotbar is created, it is anchored to the origin. It uses a GridContainer. It seems you cannot control the growth direction of the grid container, so I am wondering how I can ensure the correct placement of the hotbar and inventory in my scene. The hotbar is supposed to be centered on the bottom of the screen.
What I have tried is anchoring the hotbar to the bottom of my screen and then adding margins to the bottom and right side. I know I could just move my hotbar’s anchor in the scene it is created but I want to keep it flexible. Do I have to set the margins in code after reading the sizes or is there a way to do so in the Inspector?
Hit the “Expand” tickbox for horizontal container sizing and see what that does - I believe that’ll do what you want it to to make it all centered, but I may be wrong.
Good guess but sadly no. I think Container Sizing only handles how different elements shrink and grow if they run out of space. What I have found to work is changing the layout mode. But my top level item is Control, so it does not affect my grid.
I suppose the correct way would be to have my grid, then place it in my UI scene inside of a control/container node which I can then anchor to. But that still does not solve my issue.
Maybe I can create a resource to set the anchor points and then using that resource’s set method change the position to what I need. Seems like very bad practice to me, however.
You might wanna put it inside an HBoxContainer
or some other container that will force it to get centered, control layout is pretty messy in godot
1 Like