+2 votes

I'm working on a multiplayer game which uses the high level multiplayer API. The API relies heavily on the names of nodes when using rpc and related commands. However, in my case, the server is expected to load all active scenes, while the client only needs to load the ones relevant to that client. On both sides, many nodes are initially created programmatically. When the nodes are created, they are automatically given a name like @@2 where 2 is an increasingly incremented number based on the number of nodes created. Unfortunately, this number seems to be based on the number of nodes named automatically in the entire tree. So if the server created 2 sub-scenes which each created 2 nodes, then it has names going up to @@4, while the client only goes up to @@2. Now the names in the scene trees may no longer match, and an rpc call on node @@4 on the server which is suppose to be sent to @@2 on the server will no longer work.

Is there a way I can set the default naming scheme? For example, if it were the same scheme, but having the number based on the number of children for that specific parent node, it would work fine. Of course, I can add in explicit code to always name all nodes in all cases where it's needed, but this global solution would be better in my case. Thanks!

in Engine by (107 points)

1 Answer

0 votes
add_child( node, true )
by (2,274 points)

For future visitors who may need a bit more explanation, this answer is suggesting to use the legible_unique_name parameter of add_child. This adds the node with a name that is unique among the children of that parent (the first node type Node is named Node, the next as Node2, then Node3, etc). It does not allow you to change the default naming scheme (as you might have been looking for if you just saw the title of the question). It also does not solve the issue in the question of not having to add extra explicit code in each case where nodes are being added that need the naming scheme. However, it does reduce the amount of explicit code needed in each place down to just adding true. In my case, actually changing the default naming scheme algorithm would be better (since that solution would be safe from forgetting to add the true, especially when relying on multiple developers to do so) , but I'm guessing I won't be able to get that without modifying the engine. So this is likely the solution I will use.

Yeah, it's not a pefrect solution but i posted it because i don't know any better ;p and because it seems to be "the Godot way" to solve a problem you have.

Oh and one more thing - be careful with giving nodes names that end with a number.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.