Have button group icon when one is selected

Godot Version

4.3

so I have a script that detects when a person clicks one of the buttons

extends Control 

@export var difficultyGroup: ButtonGroup

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    for b in difficultyGroup.get_buttons():
        b.toggled.connect(toggled)

func toggled(condition):
    if condition == true:
        pass
    elif condition == false:
        pass

im not sure how to pass the button so I can change the icon
image_2024-11-02_162213018

You could maybe try using the bind method as such:

class_name Menu extends Control


@export var difficultyGroup: ButtonGroup


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
    for b in difficultyGroup.get_buttons():
        b.toggled.connect(toggled)


func toggled(condition: bool, button: Button) -> void:
    pass

(cf How to connect a list of button signals ? - Godot 4.1.1 - Stack Overflow and Godot: how to connect button signal via script - Stack Overflow)

that solved the issue thanks

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.