The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

I have Main scene, let's call it Scene A. Then I have another scene, let's call it Scene B. I instanced B in A. B (UI scene) has buttons. But when I want to connect the pressed signal to the A script, it's not there. What's the correct method to do it?

Thank you for your time!

Godot version 3.2.3
in Engine by (373 points)

2 Answers

0 votes

You want to take the scene A and write the function you want to connect too

func _sceneB_connection:

then when you instance the Scene B you want to connect that over to scene A within scene A

var bScene = sceneB.instance()
bScene.connect("SIGNAL NAME", self, "_sceneB_connection" )

If you have any other questions, don't be afraid to ask more questions!

FYI the signal name for button pressed is "pressed"

by (50 points)
edited by

B script:

func _on_button_pressed():
    #how to transfer signal to the A script? (if it were in A script, I would directly write $object.rotate as "object" is in A script)

B scene instanced as a node in A scene.
A script:

var b_scene = get_node("scene_B").instance()

func _ready():
    b_scene.connect ("on_button_pressed", self, "_on_button_pressed")

func _on_button_pressed():

Is it how that's supposed to work? I kind of understand the concept but need some guidance to make it work.

Oh, I get the logic now, in scene B I just need to keep it "pass". Let me try it.

UPDATE: I set everything as you mentioned except it returns error: Nonexistent function "instance" in base (my instanced scene name).

PS: I set:

var b_scene = get_node("scene_B").instance()

...above/before the func _ready():

0 votes


by (373 points)
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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.