Determine name of node(from group) that emitted signal

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Jayesh4Godot


I have 9 buttons added to ‘button’ group, I connected ‘pressed’ signal of each button to same signal method/function. Now, how do I determine in that signal call, which button out of 9 buttons was calling that signal? Note: I connected signals in IDE / node tab itself, not through coding.

:bust_in_silhouette: Reply From: GameSchool


What I did when I faced that problem was to add an extra string variable to the function (Can be done in code and in the UI) that has the name of the node. It’s a job you’ll have to do manually, but I couldn’t find better solutions

Yes, so the way I did with the help from ‘Discord Godot group’ was, in common signal function call, we can pass argument ( available while creating signal connect, by enabling ‘advance’ from bottom, we can decide what type of argument like int, string etc we want to pass, decide its value there), I passed button values as int like 0, 1, 2 etc. for every button then used these integer values as an index of array of buttons that I got from get_tree().get_nodes_in_group(“buttons”)

Jayesh4Godot | 2023-06-18 17:13