How to get the object which emit the signal?

Godot Version

4.2.2

Question

Hello. I have a group of buttons:
image
When they are clicked, I want the corresponding UI layer appear on the window. But I don’t want to assign a signal process function for each of the button, I want to deal with all the pressed signal in a single function. If I can get the button object which I pressed, then I can get its name and determine which UI layer should I show. However, the pressed signal does not return any object to the signal process function.
I expected there maybe some properties or methods, such as is_pressed() for button object, so that I can loop through the button list and check which button is pressed. However, there is no such method.

Look into bind(). It lets you bind a variable, e.g. your button object or some ID, to the method you want to connect with a signal.

2 Likes

I have a different approach to all that since I put my pop up panels in the same scene in which where the buttons are ( or create a separate scene for the panels then add them as a child to where the buttons that activates them belongs to). So I just use the signals for the button to show() them (they are initially hidden using hide() in _ready() or you can also do that by clicking the ‘eye’ icon in the scene hierarchy). I think this is simpler and faster.

Also, correct me If I am wrong but I am assuming that you put the buttons inside and array to see which one is pressed? I think this is complicating things.

Hope this helps, and if I misunderstood anything, just tell me!

1 Like

Yes, your solution is good, too. And I indeed put all the buttons in a list (use the .get_children() method).

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