- Edited
Hello.
I'm making an Arkanoid clone, and I'm having a issue in deleting some instantiated objects.
I have powerups that are generated when the ball collides with the blocks. Then the powerup falls, and after crossing a "deadzone", I want that specific node that crossed the zone to be deleted.
But I'm having issues in deleting the node that crossed in that instant. The problems I have encountered were it simply not being deleted; after being deleted the game crashes trying to create the next instantiated powerup (probably because the parent node was deleted, and not the child); just one powerup visible on the screen at the time (the previous one being deleted when the ball hits the next block and creating the next one, before even going on the deadzone)
One thing I suspect is that the function for creating the instantiated powerups is inside a function I created, and I can't access the instantiated variable from outside to call a queue_free(), and as I said, calling queue_free() with the way my code is structured crashes the game when the next powerup is created.
I'm also using remove_child but it doesn't delete it, so I'm a bit lost.
This is the code I'm using for the powerup:
const pwupdouble = preload("res://actors/double.tscn")
func _ready() -> void:
add_to_group('powerups')
set_meta('double', true)
#func _physics_process(delta):
# velocity.y += gravity * delta
# position.y += velocity.y * delta
func spawn_double_powerup():
var powerupdouble = pwupdouble.instance()
powerupdouble.position.x = get_parent().get_node("Ball").ballposition.x
powerupdouble.position.y = get_parent().get_node("Ball").ballposition.y
add_child(powerupdouble)
print(powerupdouble.position)
func _on_Area2D_area_entered(area):
get_parent().get_node("Pwupdouble").remove_child(self)
#queue_free()
print('count', get_child_count())