Help: OCCASIONALLY get Attempt to call function 'queue_free' in base 'null instance' on a null instance.

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

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():
	for child in children:
	trail.emitting = false
	fade_out.interpolate_property(self, "modulate", Color(1,1,1,1), Color(1,1,1,0), .9,

func delete_missile():
	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!

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

klaas | 2020-08-18 18:12

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

scrubswithnosleeves | 2020-08-18 18:16