0 votes

I have lots of instances of a node that I want to delete themselves when they enter an area.

The initial node that I have on the screen deletes itself fine but its instances do not (even though they are all being detected by the area). I've tried lots of stuff from the forum but I can't figure it out.

In my code it's known as sugar, and the area is known as bin. I've tried things like sugarinstance.instance().queuefree() but i can't get it to work. Thanks in advance.

Main

Extends Node2D

onready var sugar_instance = preload("res://sugar.tscn")

func _process(delta):

add_child(sugar_instance.instance())

sugar

func _on_bin_area_body_entered(body):

    print("Entering bin")
    queue_free()
in Engine by (15 points)

1 Answer

+1 vote
Best answer

Have you tried

body.queue_free()
by (4,157 points)
selected by

Works perfectly, thanks so much.

Can I ask what this does and why this works? And why queue_free() doesn't?

Cheers

Just queue_free() will free the node attached to the script, in this case - bin_area. But body.queue_free() will free the body entering the bin_area. You simply called queue_free() on the wrong node.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.