Area2D seems not to be connected to _on_body_entered' signal

Godot Version

4.2.2

Question

` Hi all, I am new to game development and GDScript is my introduction to code as well. Because of that, I am building an Asteroids-like game to get a grasp of the basics. For this I am following the instructions of this tutorial on YouTube, which is pretty good.

However, I would like to try something extra, which is making an asteroid disappear and spawn two smaller asteroids when a player collides with it. I wanted to use a similar method as with the laser in the tutorial. Instead of using the _on_area_entered trigger, I am working with the _on_body_entered trigger for the player.

The problem is that the signal does not seem to be connected properly and I am at a loss at what I am doing wrong. The debugger gives me the following warning:
Missing connected method ‘_on_area_entered’ for signal ‘area_entered’ from node ‘Asteroid’ to node ‘Asteroid’.

This is de code I am using in the Asteroid script:
`

class_name Asteroid extends Area2D

signal exploded(pos, size)

func explode():
	emit_signal("exploded", global_position, size)
	queue_free()

func _on_body_entered(body):
	if body is Player:
		explode()

``

This is the related code in the game scene’s script:

extends Node2D
@onready var asteroids = $Asteroids

var asteroid_scene = preload("res://Scenes/asteroid.tscn")


func _ready():
	for asteroid in asteroids.get_children():
		asteroid.connect("exploded", _on_asteroid_exploded)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	pass
	
#Spawn
func _on_asteroid_exploded(pos, size):
	for i in range(2):
		match size:
			Asteroid.asteroidsize.large:
				spawn_asteroid(pos, Asteroid.asteroidsize.medium)
			Asteroid.asteroidsize.medium:
				spawn_asteroid(pos, Asteroid.asteroidsize.small)
			Asteroid.asteroidsize.small:
				pass

func spawn_asteroid(pos, size):
	var a = asteroid_scene.instantiate()
	a.global_position = pos
	a.size = size
	a.connect("exploded", _on_asteroid_exploded)
	asteroids.call_deferred("add_child", a)

As it stands, the asteroid does disappear when a player collides with it. It does not create two smaller asteroids in its place.

I have been looking for solutions online, but I can’t seem to find any answers that really solve this specific issue.

Can anyone explain what I am doing wrong?

Since the asteroids are spawned on the same global position of the exploded one, my guess is that the new asteroids are indeed spawned, but they explode in the next frame since the player overlaps its Area2D (I’m assuming the player does not die after colliding with an asteroid). To confirm this, I suggest you to spawn the asteroids in a position far from the player. If they are shown in your game window, then what i described is the problem you’ll have to solve.