Non-unique node names at run-time

Godot Version

Godot Engine v4.6.3.stable.official [7d41c59c4]

Question

I don’t understand how this is possible but I have nodes spawning with the exact same name in the Remote tree:

I’m using a spawner for both entity types and was testing using a signal to spawn_destination.add_child(entity, true) for the ItemPickups (the entity gets passed via signal to function that adds it). The Enemy nodes are added directly from the spawner. My code works as I had hoped but I’m stumped at the non-unique ItemPickup names in the remote tree.

What… does this mean? Can I ignore this or is this a sign that I have porked something up somewhere?

Post instantiation code.

This shouldn’t happen so I’d consider it an engine bug. Searching the issues on github, it looks that something like this was reported in earlier versions and fixed. Apparently not.

I’d suggest making a minimal reproduction project and reporting it.

It happened to me in godot 4.5.1, i suppose that nodes don’t require unique names if they’re running in game, cuz nothing broke

Unique names are not required bur Godot tries to enforce them for siblings. Otherwise you may end up with two nodes having same node paths which has a high potential to cause bugs. Not sure what exactly you or op did to end up with same names, but you should take extra care to ensure that siblings don’t have the same names.

ig engine only adds unique names if it’s in engine, during runtime it probably don’t have such function and you need to implement it yourself

add_child() will always pick a unique name by doing this:

image

If force_readable_name flag is set then it will generate a unique numerical suffix:

image

hmmm i think i haven’t this way, at least when i tested it in january, maybe it’s really a bug

My first guess would be you are assigning a name to the Node. That would cause this.

The engine normally doesn’t allow it. It’ll alter the name if there are siblings with the same name already present in the tree.

I’d like to see some reproduction code.

I’ll reduce my project down and upload it when I get a moment. I’d like to know what is going on as well as it feels weird to have identical-looking nodes.

This probably the least likely but make sure it isn’t simply the case that your window is too narrow to show the entire name.

This was my first thought but I was reluctant to say it out loud.

I would say write code to get the child nodes of Pickups. Get the count.print ItemPickup object id. E.g. var child_id: int = child_node.get_instance_id() Maybe this will give you a clue.

I’m more than happy to laugh off a monumentously dumb user-error as that would be the fastest resolution. I’m still learning so not unlikely.

Here’s the test project with notes. If there is no error on my part, then I’ll submit a bug report.

I just open your project.
It seems like bug #117860.

That bug also looks annoying but I don’t think that causing this: both Enemy and Snowflake (renamed from “ItemPickup” in original screenshot here) nodes have terrible Remote Node2D: 38252053992 names in the Inspector but only Snowflakes are instantiating with non-unique names. If this was the cause then I would expect the Enemy nodes to also have non-unique names.

Can you reproduce it with a single script?

Didn’t got it reproduced in a single script, but found what’s causing it:
A scene gets instantiated, but instead of adding it to the scene tree after instantiation, one of their nodes adds itself to the scene tree (by calling an Autoload).

Example:

extends Node
@export var scene : PackedScene

func _ready() -> void:
	for i in 3:
		scene.instantiate()
# node in the instantiated scene:
extends Node

func _init() -> void:
	Autoload.add_child(self, true)

If I’m understanding it correctly, this will basically call _ready() from _init(). That’s something you don’t see every day :smiley:

I have found a good rule of thumb with Godot is never use _init() on first pass of a new object. There are a LOT of gotchas with it. Always use _ready() when you would use a constructor. Then, once your object is working, if you want to use _init() when stuff breaks, you will know it worked before, and what you changed.

There are so many things that Godot does under the hood with Nodes, and you need to have a good understanding of them before you treat them as you would classes in another language. Because they are not Objects, and people coming into GDScript often treat them as such. (I know I did.)

Also, I was kinda right. You were renaming the nodes, just didn’t know it. :slight_smile: