0 votes

How does one connect signals from other children (horizontally in the scene tree) without using the interface? I know of the connect function, but I've only used it from a parent.

Godot version 3.3.3 Stable
in Engine by (27 points)

1 Answer

+1 vote
Best answer

Suppose the scene tree is

Node
Node/Node
Node/OtherNode
Node/Button

and suppose you want code in Node/Node's script to do the job of connecting the Node/Button's pressed signal to the function button_got_pressed in Node/OtherNode's script.

Then you would write something like this in Node/Node:

func _ready():
    var button = get_parent().get_node("Button")
    var other_node = get_parent().get_node("OtherNode")
    button.connect("pressed", other_node, "button_got_pressed")

and the script on Node/OtherNode would have something like this

func button_got_pressed():
    print("button got pressed")
by (180 points)
selected by

Thank you :)

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.