+1 vote

In Godot 3.0, if I create a scene with a CenterContainer, and I set as a child of it ANY type of button, the button will be visible, but putting a Rect under it such as TextureRect or ColorRect will result in it setting the rect_size value to Vector2(0, 0), ergo, it becomes invisible.

I mean, I can create a ToolButton, set its icon to the image I want and set its enabled_focus_mode value to "None", and that'll work for me, but what I want to know WHY this is happening.

Anyone know?

in Engine by (186 points)

1 Answer

+2 votes
Best answer

When you use Containers, you have to make sure what you put in it has a minimum size, otherwise they will often be shrunk to zero. This is because you cannot define the normal size of controls, since the Container is going to dynamically adjust it (also note the size is also a result of the application of anchors and margins).
Button doesn't shrink completely because it probably has an internal minimum vertical size of some sort (you will see the width will shrink anyways).

by (29,088 points)
selected by

Kind of annoying that we have to setup an explicit minimum size. Do you know if there are plans to eventually setup resizable positions/sizes/scales based on defined percentages, such as "always be 30% as large as the parent Container".

I believe you can do this by entering numbers between 0 and 1 for the anchors, but if you do it I would advise to not use CenterContainer. You can setup the anchors in such a way they center the control ;)

enter image description here

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 Frequently asked questions and 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 [email protected] with your username.