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!