How to create a button which acts like a container?

Godot Version

Godot 4.6.1 (mono)

Question

I’m working on a small RPG game where some elements need to act like buttons (with normal/hover/pressed/disabled states) but can contain complex information.

So I wonder how to use a Button control node but to force it to be working like a Container?

1 Like

Display the complex information in a rich text label that is displayed over the button.

Turn off mouse input for the label.

1 Like

Well in my case i use lable overlapped by button which is falt. So the label and it’s text is visible. And it’s act like button.

Yea This is also useful :+1:

Make something like this:

PanelContainer
  Button
  VBoxContainer (or some other stuff)
    Label
    Label

Set the Mouse/Filter of VBoxContainer and it’s content to Ignore so that the mouse clicks go to the Button.

1 Like

I think a ButtonContainer should be added to Godot, this kind of container has been asked about a number of times and other game engines feature such an object.

For now a workaround is to create a margin container for both your button and another container with the contents of the button.

3 Likes

Thank you everyone for your answers :folded_hands:

The best solution I tried is to create a PanelContainer node, with a StyleBoxEmpty override, which contains the Button as its first child, and the real container as the second child.

So far, a ButtonContainer will be the best solution ; hope it will be implemented in further versions.