Duplicate nodes

Godot Version

godot4

Question

room0_0:<Node2D#30249321814> and @Node2D@2:<Node2D#32329696620>
these are the same nodes being printed except one is described as room0_0 and the other is described as @node2d. they should both be called the same thing.
here is the code for spawning rooms

@export var roomDestination = Vector2(0, 0)
@onready var room = preload("res://room_0_0.tscn")
@onready var NODE_WORLD = get_tree().get_root().get_child(0)
@onready var NODE_PLAYER = NODE_WORLD.get_node("player")
var myPos = position


func _on_door_area_body_entered(body):
	if body.name == 'player':
		var instRoom = room.instantiate()
		instRoom.position = myPos
		NODE_WORLD.call_deferred("add_child", instRoom)
		print("created")
		print(NODE_WORLD.get_children())

You could set the .name property to whatever you want. However I am pretty sure two nodes cannot have the same name if they are children of the same parent node. Also its not a good idea to identify a node by its name, use its type instead.
Like this:

if body is Player
1 Like

Use @numbers11 suggestion above. Which utilities the class_name not the Node name.

Adjacent Nodes (siblings) can’t have same name.

If they have the same name you will get a random basic name that is incremented with a number e.g. @node1 @node2 etc

This is because they need to be uniquely addressed. Much like a filesystem. There are many operations in Godot that use the NodePath to access nodes and if they have the same name they you will have undefined behavior.

If you want human readable you need to add an extra parameter to your add_child call. Set the force_readable_name to true this will get ret of the @ symbols and use the name you provided, or default name, plus an integer, if there are more siblings with the same name.

godot decided to deledte my scenes in the scene folder for some reason so i geuss i gotta make a whole new project.
image
image
image

k i fixed th missing files

I have corrupted scenes before, especially if I’m jumping around with different versions of Godot on the same code base. I typically fix it by closing and reopen the editor.

1 Like

yeah, it sucks that godot just outright deleted files. had to install a file recovery software just to find it. prob gonna bcak up my projects to github from now on