Non-unique node names at run-time

Regardless of OP doing weird stuff, I’d still classify this as an engine bug if there were no complaints in the debugger.

Printing the node’s name before and after add_child():

before: 
after: Node
before: 
after: Node2
before: 
after: Node3

Scene tree after every add_child() and at the end of the for loop:

 ┖╴root
    ┠╴Autoload
    ┃  ┖╴Node
    ┖╴Main

 ┖╴root
    ┠╴Autoload
    ┃  ┠╴Snowflake
    ┃  ┖╴Node2
    ┖╴Main

 ┖╴root
    ┠╴Autoload
    ┃  ┠╴Snowflake
    ┃  ┠╴Snowflake
    ┃  ┖╴Node3
    ┖╴Main

 ┖╴root
    ┠╴Autoload
    ┃  ┠╴Snowflake
    ┃  ┠╴Snowflake
    ┃  ┖╴Snowflake
    ┖╴Main

So the scene instantiation seems to set the node names after their _init() (when they are already part of the scene tree, in this specific case).

I guess it’s fine for scene instantiation to not account for this, but trying to add nodes to the tree before their scene is fully initialized should probably cause an error then.

So where/when does Godot do the name check to iterate a number on the name for uniqueness? The core of this problem is I’m doing something that seems to side-step that whole thing. If it renames Node2 to Snowflake, shouldn’t the engine see there’s already a Snowflake in the tree and make it Snowflake2?

I agree; there’s no errors/warnings in this test and only picked it up when I was investigating the weird/stupid idea I had, which I ended up ditching.

Should I post this to Godot’s issues or is it still a bit too grey on whether it’s a bug (since it seems I was doing something rather odd)?

It’s strange. If you can, try to reduce the reproduction example even further, as much as possible. That way it’ll be easier to pinpoint the culprit.

I’d expect the check is done by add_child() but could also be happening in the scene tree code…

I looked into source code.

Node::add_child() does the name validation and then calls Node::_add_child_nocheck() which actually adds the child (without checking, as the name suggests).

The only other place in the codebase where Node::_add_child_nocheck() gets called is from… surprise… PackedScene::instantiate(), but this time without name validation.

So it appears that you (and the engine) somehow managed to tangle things up to such a degree that instantiate() adds the node to the scene tree.

You should definitely report this. Again - try to make the reproduction example as small as possible.