Why might queue_free() not work and not give any error message?

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

I’ve been creating a script to create a “damage zone”, which is just a sprite with a collision circle as a scene. I instantiate it with this code:

damageZone = load("res://Scenes//DamageZone.tscn").instance()

and this works fine, I can see the sprite appear, and walking into the zone sends the right signals, i handle damage and all that. The problem comes when trying to delete the zone with this code:

if damageZone != null and is_instance_valid(damageZone):
    print("before delete")
    print("after delete")

In the console, I can see both before and after delete messages, but the sprite is still there, and walking into it still causes damage. There are no error messages given whatsoever, what might be causing this?
I’ve tried using other methods to delete as well, things like free(), remove_child(), but these don’t work either.

Not an answer, but when / how do the the two snippets you posted above get called?

jgodfrey | 2022-03-30 19:06

probably, you couldnt call the node which you want to delete. Could you please test" damageZone.position.x+=100 " to see if the node moves when called or try to use get_node(“demageZone”)?

horsecar123 | 2022-03-30 19:50

:bust_in_silhouette: Reply From: Inces

This must be another instance of damage zone. Didn’t You forget about some scene of damage zone made in editor ? Or You created it somewhere else in a code.

Enter Remote Tab during your project running and try to manually find your intruding damagezone there. If You can’t find it - make every damagezone print get_parent() on _ready(). You might be able to find an orphaned node this way. Finally, print SELF on area_enter and simply notice how many different IDs are printed

Thanks so much, as it turns out I had forgotten to delete a test version of the zone from the scene, stupid mistake. Thanks for the help!

SneakySteve | 2022-03-30 20:39