Godot queue_free() instancing problem

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Pacers

So I’m creating a simple 2D breakout game and I have instanced the bricks in code. I created somewhat of a grid of bricks but the problem is that when the ball hits any one of the bricks then all the bricks are gone/deleted.

func spawn_bricks(row,column):
var pos_x = 64
var pos_y = 0
#column
for i in range(row):
	pos_y += 32
	pos_x = 64
	#row
	for j in range(column):
		brick = BRICK_SCENE.instance()
		brick.add_to_group("Bricks")
		brick.position = Vector2(pos_x, pos_y)
		pos_x += 64
		add_child(brick)

#Rigidbody2D Ball uses signal body_entered and deletes brick  
func _on_Ball_body_entered(body):
	if body.is_in_group("Bricks"):
		call_deferred("free")

The bricks are ordered in rows and columns so ‘spawn_bricks(3,5)’ would spawn 3 rows of 5 bricks. Is there any way where if the ball collided with one brick then that brick is deleted and not the whole grid.

:bust_in_silhouette: Reply From: denxi

Your code is deleting the brick manager, not the bricks. Try changing the code to

func _on_Ball_body_entered(body):
    if body.is_in_group("Bricks"):
        body.call_deferred("free")

You need to get the individual brick to run the free code.