0 votes

I'm instancing a button in my scene and I want to be able to connect the _pressed() signal to the main scene it's being instanced in. How can I do this without a singleton?

I could have the button emit a signal in the _ready function and then connect it in the main script, but I have no way to access the button without making it a singleton. Is there a way to access it only after the button is instanced?

asked Jun 12 in Engine by DigitalDrako (108 points)

1 Answer

0 votes

Sure you can't connect it via

$MyButton.connect("pressed", self, "my_function")

like explained on this page?

answered Jun 12 by adabru (70 points)

No, MyButton is not a child (until it's instanced) so using $MyButton wouldn't work

I did solve it however by using:

MyButton = button.instance

this works the same way as $MyButton, at least how I've been using it

Nice you solved it!
So you managed to get a reference to the button node.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.