My scene moves when adding or fleeing a child node

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

(Sorry for my bad english)

I have this problem when im tring to create or delate a child item node, the entire frame seems to flicker for an instance before returning to normal, im using Node2D for items and slots, i notice is only when adding and fleeling , anyone know why?

Here is some of the script

func add_to_inventory(item_id:String,amount:int):
var on_inventory=false
for child in get_child_count():
	if(!get_child(child).is_empty):
		var item_amount=get_child(child).get_child(get_child(child).get_child_count()-1).amount
		var item_max_amount=get_child(child).get_child(get_child(child).get_child_count()-1).max_stack
		if(item_id==get_child(child).item_id&&item_amount<item_max_amount):
			if(item_amount+amount>item_max_amount):
				var overload=item_amount+amount
				overload-=item_max_amount
				var to_add=amount-overload
				amount=to_add
				fix_overload=overload
				add_overload=true
				overload_id=item_id
			on_inventory=true
			get_child(child).get_child(get_child(child).get_child_count()-1).change_amount(amount)
			break
if(!on_inventory):
	for child in get_child_count():
		if(get_child(child).is_empty):
			var item=item_template.instance()
			item.init(item_id,amount)
			item.position=get_child(child).get_child(get_child(child).get_child_count()-1).position
			get_child(child).is_empty=false
			get_child(child).item_id=item_id
			get_child(child).add_child(item)
			break
if(add_overload):
	add_overload=false
	add_to_inventory(overload_id,fix_overload)