Changing the default automatic node naming scheme (for programmatically created nodes)?

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

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!

:bust_in_silhouette: Reply From: hilfazer
add_child( node, true )

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.

shianiawhite | 2018-05-13 14:10

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.

hilfazer | 2018-05-13 15:01

1 Like