0 votes

I currently have a button which is smaller than the bounds of the HBoxContainer it is inside of, so it is very awkwardly anchoring to the top left of the container. I don't seem to be able to change the anchors like I used to in order to make it snap to center left, even through code, so is there a way to make them snap to the center left of the container? Any attempts to make it do so through code seem to be overridden by the parent, so I can't do it "manually" with some math either. Changing the alignment property of the HBoxContainer also doesn't work, I assume that changes alignment along the x axis rather than y?

in Engine by (46 points)

1 Answer

+1 vote

Changing the alignment property of the HBoxContainer also doesn't work, I assume that changes alignment along the x axis rather than y?

Correct. For VBoxContainer it's the y-axis instead.
So one way to achieve what you want would be:

- VBoxContainer (Alignment: Center)
  - HBoxContainer
    - Button

Alternatively you can keep your tree as is and change the vertical size flags of the Button from "Fill" to "Shrink Center".

by (10,255 points)

Setting the size flag did exactly what I needed, and also saved the headache of changing node paths in scripts. Thanks.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.