+1 vote

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()
get_parent().add_child(damageZone)

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")
    damageZone.queue_free()
    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.

Godot version 3.4.2
in Engine by (53 points)

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

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")?

1 Answer

0 votes
Best answer

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 getparent() on _ready(). You might be able to find an orphaned node this way. Finally, print SELF on areaenter and simply notice how many different IDs are printed

by (7,281 points)
selected by

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!

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 Frequently asked questions and 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 [email protected] with your username.