+3 votes

I'm trying to anchor a button to scale horizontally with the viewport, and I'm using stretching mode disabled, however my control does not seem to respond to anchors at all, it's anchored as "End" to the right, yet when I scale it horizontally it just stays there.

in Engine by (65 points)

I think this little tidbit should have been included in the Godot documentation about anchors & margins. Would have saved me the past several hours trying to get things to work correctly parented with Node2D or Control nodes.

Thanks for the heads-up!!

3 Answers

+3 votes
Best answer

Anchors work fine for me as long as I put all GUI nodes inside a CanvasLayer.

by (306 points)
selected by

Oh right the CanvasLayer, I completely forgot about that, I'm deep today, thanks!.

0 votes

It is working fine for me, I think you might ran into the same problem as me.

Anchor is working only if that ui control is child of ConvasLayer. if it is not child of ConvasLayer then it will show incorrectly for different screen size.

the best scene hierarchy is

Node2D (root)
- ConvasLayer (HUD)
- ConvasItem (Button, Text, etc..)
- Game Objects (sprite)

by (66 points)
0 votes

I experienced this quite often till I realized the problem was that I was resizing UI elements that were not the root node.Resizing a child node affects the anchoring as the parent node still keeps the original scale of the child node.So if you need to resize your UI element do it ONLY with the Root node of your scene.

by (22 points)
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.