0 votes

I have a button, which emits a pressed signal. I would like to handle it in another node (button's sibling), while passing the reference to the button being clicked.

I tried:
1. Connecting the signal via the engine's UI, but didn't see the option for an extra self argument there.
2. Connecting the signal like this:

var Character = preload("res://KinematicBody2D.tscn")

# Called when the node enters the scene tree for the first time.
func _ready():
    connect("pressed", Character, "on_button_toggled", [self])

following this example, but I got this error:

Error calling method from signal 'pressed': 'PackedScene::on_button_toggled': Method not found.

Even though I defined on_button_toggled in the KinematicBody2D.

I also saw this question, but there the handler is the same object, which I suspect to be a problem here.

A related question: is there a way to do this without branching the node as a separate scene? I don't have another reason to do this for this KinematicBody2D.

Godot version v3.1.1-stable
in Engine by (75 points)
edited by

1 Answer

0 votes

To answer my own question: The problem with the above is that Character may not yet be in the tree. When I connected the button to the kinematic body in their common parent, everything worked as intended.

by (75 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 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 webmaster@godotengine.org with your username.