Topic was automatically imported from the old Question2Answer platform.
Asked By
tadpolily
extends VBoxContainer
var button1
var button2
func _ready():
button1 = Button.new()
add_child(button1)
button2 = Button.new()
button2.set_size(Vector2(500,500))
add_child(button2)
I can’t seem to resize the buttons that I add to my VBoxcontainer either through code
or through adding and resizing them manually. They all the same width. Is this by design?
VBoxContainer and HBoxContainer by design both try and reduce the size taken up by children Control nodes as much as possible. Because of this, to ensure that a child Control node doesn’t collapse itself you need to set the rect_min_size property instead of the rect_size property.
One caveat is that the width of a control in a VBoxContainer will always be fixed to the width of the VBoxContainer, and the same with height and HBoxContainers. There are ways around this though, such as having a Control node as the direct child of the WhateverBoxContainer, and then a Button as a child of the Control with a smaller width or height.