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 a hard time trying to communicate using custom signals. I have a group of Objects that I'm trying to communicate clicks to player.
extends Sprite

func _on_object_clicked(obj):
    print("object clicked", obj)

extends Sprite
var player_ref = null
signal object_clicked

func connect_clicks_to_player(player):
    print("connecting ", self, " to player ", player)
    connect("object_clicked", player, "_on_object_clicked")
    #player_ref = player

func on_input(viewport: Viewport, event, shape_idx):
    if event is InputEventMouseButton and event.is_pressed():
        print("emiting signal", self)

I am calling connect_clicks_to_player in a singleton. I see connecting being printed, with correct nodes, emitting signal being printed, but not _on_object_clicked in Player. Player also claims in get_incoming_connections that this signal is connected.

I also tried moving the signal to the singleton class, following this answer, but it didn't change anything.

At the same time, when I stored the reference to the player directly instead (uncommenting the two lines) code runs correctly. What am I doing wrong?

Godot version 3.1.1-stable
in Engine by (143 points)

2 Answers

0 votes
Best answer

I don't know why, but turning the engine on and off fixed it. ¯_(ツ)_/¯

by (143 points)
0 votes

If that script is in the Singleton, from another script, access the, and then declare the connect_clicks_to_player(player) function in the_ready().

by (353 points) is not a singleton. Objects are constructed dynamically. I have a separate Singleton class, where, after instantiating the Objects, I'm calling connect_clicks_to_player. As I wrote above, it confirms being called, but emitting the signal has no effect.

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.