Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | sygi |
I have a hard time trying to communicate using custom signals. I have a group of Object
s that I’m trying to communicate clicks to player.
Player.gd:
extends Sprite
func _on_object_clicked(obj):
print("object clicked", obj)
=====
Object.gd:
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)
emit_signal("object_clicked")
#player_ref._on_object_clicked()
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?