0 votes

Hi all!

I am trying to remove SOME (but not all) children from an Aread2D node. I have done this by making an onready var list of $children I would like to delete and iterating through each object with queue_free (Shown below).

This usually works. Occasionally, however, (like 10% of the time) when I run the fade_trail function I get the aforementioned error. This is unaffected if I onready var each child separately and don't use a list.

Any ideas on what is causing this? Is there a simple solution I am missing? If you feel extra helpful, read under the code block.

onready var children = [$Sprite, $CollisionShape2D, $WobbleSound]
onready var trail = $CPUParticles2D
onready var fade_out = $Tween

func fade_trail():
    set_physics_process(false)
    for child in children:
        child.queue_free()
    trail.emitting = false
    fade_out.interpolate_property(self, "modulate", Color(1,1,1,1), Color(1,1,1,0), .9,
        Tween.TRANS_QUINT, Tween.EASE_IN
        )

func delete_missile():
    fade_trail()
    get_parent().add_child(explode)
    explode.global_position = self.global_position

I am doing this so that the particles following a projectile don't delete immediately when the projectile hits an enemy, but instead fade away before removing the entire node. If there is an easier way to do this, lmk!

in Engine by (586 points)

Hi,
are you sure that deletemissile() is not called twice sometimes? Then the children would be freed allready and the queuefree call would fail as descripted.

That was it! I actually figured it out right before you posted. Thanks for the reply!

Please log in or register to answer this question.

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.