Why is is_queued_for_deletion() not working?

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

I’m making a tower defence game, this is a tower script:

var target = null
var can_shoot = true

...

func _process(delta):
	if not can_shoot:
		return
	
	var creeps = get_tree().get_nodes_in_group("Creeps")
	
	if creeps.size() == 0:
		return
	# version A: ------------------------------------------------
#	target = null
	target = creeps[0]

   # version B: ------------------------------------------------
#	if target == null or target.is_queued_for_deletion():
#		print("####### IF")
#		target = creeps[0]
#	else:
#		print("####### ELSE")
	
	# shoot logic, including target properties + can_shoot, timer update
	...
	

target is reference to a creep scene inscance. All creeps belong to “Creeps” group. I delete a creep with queue_free().

I get different errors, when I use code block VERSION B, but it works fine with VERSION A. Sometimes it’s “already deleted node” error, sometimes var target holds children of creep scene. It looks like .is_queued_for_deletion() is not working (). Why? Is it normal that after queue_free target holds reference to childen nodes? What is best practice here?