@ symbols being added to node name

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

I’m getting some weird behavior when naming/adding child nodes that I have instanced.

My game logic happens in a tilemap, all the animations are in pawn_scene. I make levels as seperate tilemaps and simply load their content into the current tilemap.

I then instance a pawn_scene, matching each cell in the tilemap. I rename then to match the cell coordinates to access them easily.

Somewhat randomly, @ signs are added in my node names.

func load_level(level):
	var level_to_load = get_node(str("../Levels/",level))
	clear()
	for child in get_children():
		child.queue_free()
	for pawn in level_to_load.get_used_cells():
		set_cellv(pawn, level_to_load.get_cellv(pawn))
	instance_pawns()

func instance_pawns():
	for pawn in get_used_cells():
		var entity = pawn_scene.instance()
		entity.position = pawn * 64
		entity.name = str(pawn)
		print(entity.name)
		entity.position.x += 32
		entity.position.y += 32
		add_child(entity)
		if get_cellv(pawn) == 1:
			entity.change_color()
		pass

some levels load fine, some have @ on all child nodes, some are mixed.

I fail to see where I’m making a mistake. Am I missing something or is there some quirk to naming nodes?

Any help would be greatly appreciated. Project files:
https://drive.google.com/file/d/1haahDIkbC-4dKHbfLe0JMQ9PyfsjziSu/view?usp=sharing

:bust_in_silhouette: Reply From: Inces

Children of one parent can not have the same name. When it would happen, Engine adds @signs before their original names, then numbers, and even more @. That means at any moment You have 2 children of the same name. Perhaps You add one before you erase old one. Or You just have adding child uncoordinated with inastancing and two the same are added.
Generally it is definitely better to use real properties, metadata or having positions in one solid dictionary.

Indeed you’re right.

I am removing nodes before adding new ones, but the new ones are added too quick, adding slight delay gives time to flush the old ones as a quick fix.

I’ll look into a more sustainable way to manage my level loading and unloading. I haven’t tried dictionaries yet, they seem like the best solution to “tag” the nodes with an easy to find name.

If someone else stumbles onto that issue, I’ll add that you can tell Godot to use “legible_unique_names” as a second argument and using add_child(). You won’t get any @ signs but a “2” will be added after the node name if it’s a duplicate.

add_child(node: Node, legible_unique_name: bool = true)

Pumpkinwaffle | 2021-12-19 10:51

Cool, I didn’t know that method :slight_smile:
You could also eventually handle it with trim_prefix/suffix method of String class, but that is a hassle :slight_smile:

Dictionaries are pretty much the same what You are trying to do, but in form of compiled structure. Keys of dictionaries can never be the same. Trying to add key, which name already exists in dictionary, instead replaces the value of the one already exisiting. Big feature of dictionaries is that You can have other dictionaries as a values for keys, allowing You to make large nested data.

Inces | 2021-12-19 13:20