My Signals aren't working :(

Yo! What’s up! I’m new to Godot and game development in general and I’m making a simple game about falling eggs and you collect them to earn points. Right now I’m trying to implement a score system by emitting a signal whenever an egg is collected, however the signal doesn’t seem to go through. The function for deleting the egg and printing the first text work, so one would imagine that the code emits the signal, however in the score counter script it doesn’t appear the print anything or update the score.


Is the Area2D with script white_egg.gd duplicated or instantiated during the game? If so the signal is not connected unless you add code to connect it’s signal after instantiation.

white_egg.gd is instantiated during the game, but to clarify since it happens as the egg spawns in wouldn’t it always happen prior to it emitting the signal? Apologies if I’m simply confused :sweat_smile:

There is a difference between the spawned eggs and the one you see in the editor, only the one in the editor has a connected signal. The instantiated eggs must have their signal connected after instantiation

var white_egg = preload("yada yada").instantiate()
# connects white egg's `point` to scorecounter's function `whiteEgg`
white_egg.point.connect($scorecounter.whiteEgg)

Make sure to paste code samples instead of screnshots

1 Like

This is my current code for the egg, and the first egg that spawns in does update the score (Woohoo!!) but after that first one anytime I pick up an egg that was spawned in later would give me two errors. If I make it so that the first line of code after the variable doesn’t run then the game doesn’t get the two errors, so I just gotta figure out what’s wrong with that line lol :joy:

func _on_body_entered(_body: Node2D):
	var _white_egg = preload("res://Scenes/White Egg.tscn").instantiate()
	_white_egg.point.connect(%scorecounter.whiteEgg())
	queue_free()
	point.emit()
	print("Don't work...")

This code should be when the egg is instantiated, not _on_body_entered, I gave the first line as a hint that it should follow in this script.

var _white_egg = preload("res://Scenes/White Egg.tscn").instantiate()

Second, note how I do not use whiteEgg() but whiteEgg, omitting the parenthesis is important as you do not want to use the function right now, only give it to the connection.