"get_tree().get_current_scene().get_name()" returns scene name with "@" inside

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

Hi, I’m using a code that gets the name of the current scene using:


The thing is that the scene in question is called “World2”, but this function returns @World@2@”, other times it returns @World@2@2” or @World@2@3” randomly.
The thing is that it only happens to me with this scene, since with the others it works perfectly.

help pls

:bust_in_silhouette: Reply From: jgodfrey

From the docs for the Node.name property (which is what’s returned by your get_name() call):

The name of the node. This name is unique among the siblings (other
child nodes from the same parent). When set to an existing name, the
node will be automatically renamed. Note: Auto-generated names might
include the @ character, which is reserved for unique names when using
add_child. When setting the name manually, any @ will be removed.

I’d guess that you have more than one instance of your World scene in the tree at the same time? If so, that’s perfectly fine, but the engine is ensuring that each instance has a unique name.

but i am not using any add_child() method

Waffle_32 | 2023-03-06 15:50

How did the nodes get into the tree? Maybe you added them in the editor? How many instances of the node in question are in the tree (as siblings)? An image of your scene tree (containing the relevant nodes) would be helpful.

jgodfrey | 2023-03-06 15:54

Also, generally when this sort of things comes up, the issue is that the poster has code that relies on the specific name of a node. Generally, that’s not good practice and there are likely better ways to identify nodes - depending on the situation…

jgodfrey | 2023-03-06 15:56

Since I didn’t know how to change the name of the scene, I clicked on save scene as and changed the name, then deleted the original and so I was left with a duplicate scene with another name, could this have influenced it?

Waffle_32 | 2023-03-08 18:45