A new node is created to be the parent to an instance

Godot 4.5

Im somewhat mystified.

@export var item = load("res://scenes/item.tscn")

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT && event.is_pressed():
			add_item()

func add_item() -> void:
	print("beep")
	add_child(item.instantiate())

thats all thats happening.

kuva this is the tree. script is on the Inventory vbox.

this is what happens in remote view after i click once.

And i also print two beeps. So the script works, except it does it twice and creates a copy of my inventory node as a direct child of the root, where it puts the second item. I have no clue whats happening.

I think you added your Inventory as an Autoload. That’s why it’s loaded twice - first time as an Autoload and second time within your main scene.

Your Inventory shouldn’t be an Autoload.

1 Like

Yup, that was it. Thanks

1 Like