Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance-names can not include '@' signs #27608

Open
sschellhoff opened this issue Apr 2, 2019 · 10 comments
Open

Instance-names can not include '@' signs #27608

sschellhoff opened this issue Apr 2, 2019 · 10 comments

Comments

@sschellhoff
Copy link

Godot version:
3.1

OS/device including version:
Arch linux

Issue description:
If you make multiple instances of the same nodetype, godot names the first instance after the node type and the other ones are prefixed with an @ and suffixed with an @ and a number. For example, if you create two Nodes of type GraphNode, the first instances name is "GraphNode" and the seconds name is "@graphnode@288" or something like this.
If you want to rename an instance and it does include an @, the @ gets discarded.

var node = GraphNode.instance()
add_child(node)
node.set_name("@GraphNode@200")
print(node.get_name()) # prints GraphNode200

This is problematic if you want to save and load node data and node-connections.

Steps to reproduce:
Make an GraphEdit, attach a script to it. In the script, create an instance of GraphNode and add it as a child. Set it's name to "@graphnode@100". After that, print the name of the nodes instance. The name is "GraphNode100" and not "@graphnode@100"

@akien-mga
Copy link
Member

Why do you want to set such name though? @ is used by the engine internally to indicate nodes that were instanced without being given an explicit name, i.e. we don't actually care about their name. @ is thus a reserved symbol so that you know that nodes with a @ have all been created this way at runtime.

@slapin
Copy link
Contributor

slapin commented Apr 5, 2019

Well, just name all your instances you care for in unique way so that on the same level of the tree there is no duplication. This way you will now how to access each instance. I use that to save and restore from/to json.

BUT there is no easy to find documentation on which symbols I can safely use in instance names. The reason I ask about this is sometimes I need annotations for objects to which I add special handling (during import or runtime). For example all names ending in _spawn are spawn points and get attached script. But also I need to specify settings so that to select what in particular to spawn and other things. So I want to have some structure of name with separators. Using some characters would be nice to make that expressive. For example having something like "char_spawn#role=gplayer#team=1#group=spawn#id=10" would be nice as there is no other nice way to produce annotations in 3D software for engine to use.

@Dogpot
Copy link

Dogpot commented May 18, 2019

Ran into this particular issue when writing a save system, took a while to understand what was happening too. The @ gets serialized just fine, but breaks things down the line when you try to use the name or node path for something (like parenting other nodes) as the @ gets silently stripped, leaving you none the wiser. I guess the proper workflow is to explicitly name all the instanced nodes that get used this way, but would've still been nice to know...

@xukongwen

This comment has been minimized.

@Calinou
Copy link
Member

Calinou commented Mar 5, 2020

@xukongwen Please ask support questions on one of the other community channels, not here.

@aaronfranke
Copy link
Member

BUT there is no easy to find documentation on which symbols I can safely use in instance names.

Ideally we would use something like XID_Continue (see this and click category search), not sure what Godot currently does (personally I've only ever used English letters and numbers for node names).

@slapin
Copy link
Contributor

slapin commented Sep 24, 2020 via email

@nezvers
Copy link

nezvers commented Feb 3, 2021

I run into this problem making a save system for color palette generation app using GraphNodes and connections are made knowing the names. This symbol shouldn't be there if it's not allowed to be used naming nodes in runtime.
Either remove practice from the engine side or give access to use it.
Because of that, I'm forced to do a workaround:

func _ready()->void:
    name = name.replace("@", "")

@dalexeev
Copy link
Member

BUT there is no easy to find documentation on which symbols I can safely use in instance names.

Quotes from the current docs:

String.validate_node_name()

Returns a copy of the string with all characters that are not allowed in Node.name removed (. : @ / " %).

Node.name

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.

Node.add_child()

If force_readable_name is true, improves the readability of the added node. If not named, the node is renamed to its type, and if it shares name with a sibling, a number is suffixed more appropriately. This operation is very slow. As such, it is recommended leaving this to false, which assigns a dummy name featuring @ in both situations.

I think the solution to this issue is to add cross-references (and possibly duplicate the list of prohibited characters into the Node.name description).

Related:

@Anutrix
Copy link
Contributor

Anutrix commented Oct 5, 2023

This is especially apparent when collision shapes are created from Mesh Instance. These will start with @ but if we click to rename and press Esc, it'll change _ with no way to go back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants