Sibling nodes must have unique names. To speed up the instantiation of the nodes when adding them to the scene tree a generic name will be generated if it collides with another sibling node name unless you set force_readable_name to true when adding it with Node.add_child() . In this case the name will still be unique between its siblings being something like CardBase@2 for example.
Is there any way to get the object’s class_name that I have specified without setting force_readable_name?
Effectively, what is the mechanism of the “is” operator in the line if child is CardBase
and can I use a function call (without overrides) without explicitly needing to be aware of the type I’m checking for?
It’s not the class_name the name the node will try to use. It’s the name of the root node of the scene you are instantiating the one that it will be used. For example, if the root node of the scene is named Potato it does not matter which class_name the script attached to it will have. It will try to use Potato
I’m not sure I understand what you want to do. It’s not possible to get the class_name in Godot 4.2 but in Godot 4.3 you can use Script.get_global_name() to get it.
When you refer to name here, are you referring to the name as it appears in the scene tree? The root name is CardBase, and that is the scene I am instantiating, yet it still returns “@MarginContainerX”
I was just trying to see if there was an alternative to checking for a (named) node type.
e.g. something along the lines of
for child in children:
print(child.name)
In the above, I get the following output for e.g. 4 instantiations:
As pointed before, you need to pass true to the parameter force_readable_name in the Node.add_child() function so it uses the name of the root node of the scene you are instantiating and adding.
The name of the node has nothing to do with the class_name you give a script.
The only way for now to know if a node is of an specific type or extends from one specific type is using the is keyword as you said in your first post.