Topic was automatically imported from the old Question2Answer platform.
Asked By
LemonAIDS
Hate to ask such a stupid question but I’ve spent too long searching for a way to make this work. They’re checkboxes, right? There is no magical “ButtonGroup”, adding a group to each checkbox does nothing, putting them in a container does nothing.
Is there a way to make radio buttons in Godot 3.0? TIA
I figured it out (I actually had a working example in the project I was working on…so dumb xD).
Create a new CheckBox and it has a “Group” property. Click the arrow, create a new ButtonGroup and name it. Then click the arrow again and Copy. Make another checkbox, click arrow → Paste. Radio buttons.
I don’t know if there is an official way to do this, but i’ve done this way:
First, i create a new scene with a CheckBox node, which i call RadioButton, and i save it as RadioButton.tscn. I add to it a script with this content:
extends CheckBox
func is_radio():
pass
func _ready():
pass
func _process(delta):
pass
func _on_RadioButton_toggled(button_pressed):
if button_pressed:
for child in get_parent().get_children():
if child.has_method("is_radio"):
child.pressed = false
pressed = true
else:
pressed = true
Be sure you connect the toggled() signal to _on_RadioButton_toggled() function.
Then i instantiate in the scene i want the radio buttons as many as i want.
Note: I think this would work better if we use groups, but i’ve been using this way with no trouble at all.
I was so sure there would be a way to just have the checkboxes treated as radio buttons, but this is an excellent workaround. Thanks!
LemonAIDS | 2018-12-06 04:47
You are welcome! Could you select my answer as correct then? So others can see it works.
This is an older question, but the only answer doesn’t seem to be up-to-date.
If you create a CheckBox node, under the BaseButton section in the inspector you can create/define a Group (button group) for it. Copy this group for every radio box in the same group.
This is all you need to do, now the buttons act as radio buttons.
even normal button works, if toogle mode checked, tested in godot 3.1.1