Get input from an instanced scene

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Not_a_Robot
:warning: Old Version Published before Godot 3 was released.


I created a scene to use it as a custom Popup dialog.
Its structure is:


I would like to know (from the root scene that will load this custom scene) when and which of the buttons was clicked. How do I approach this, please?


:bust_in_silhouette: Reply From: Zylann

When you have to communicate with the parent scene, a nice approach is to use signals.
So you can have a script in your Panel that basically exposes signals this way (partial code):

signal choice1_selected
signal choice2_selected

func _on_Button1_pressed():

func _on_Button2_pressed():

Then in the scene that contains this panel, you can listen to those signals by connecting a function to them.

You could connect directly to the buttons, but it’s as wrong as accessing private members of a class IMO, and it would break if you change or rename the buttons later.

Just for possible future searches:
In the scene that contains the panel:

get_node("Panel").connect("choice1_selected", self, "method_to_call")

And yes Zylann, I asked this question because I thought it was a bit awful to connect the buttons directly.

Thank you very much! :slight_smile:

Not_a_Robot | 2016-07-16 00:24