Button Can't Be Clicked If Children Are PanelContainer

Godot Version

4.2.2

Question

This is my current scene set-up.

The problem is, that when I load the scene I cannot click on the button unless I position my mouse between the separation spaces from the HBoxContainer.

image

Additionally, I resized the button manually to contain the children, is there a way to make it a container so that it automatically adjusts to the size of the children? I’ve always suffered with this and positioning the UI correctly on screen when it’s not a container. It’s a bit confusing.

I have this general problem with buttons and their children. I understand all the control nodes in a separate context. When I try to make them come together like this it just doesn’t work and I don’t understand why. Any help is appreciated.

Any help is appreciated!

set the mouse filter to Ignore of the h box container

Thank you! This fixed the clicking.

Is there a way to get it to automatically resize depending on the size of the children like a container?

1 Like

Buttons are not containers so they will not resize for their children. However, if you make them siblings instead and have another container as the Button’s container, the button will resize to fit the parent container which resizes to fit the other children.

1 Like

I think it is not possible but you can do this with codes

Any update?

1 Like

You can try this:

var total_size = Vector2.ZERO

func _ready():
   auto_size()

func auto_size():
   for child in get_children():
      if child.size.x > total_size.x: total_size.x = child.size.x
      if child.size.y > total_size.y: total_size.y = child.size.y

   size = total_size
1 Like