Siccity / xNode

Unity Node Editor: Lets you view and edit node graphs inside Unity
MIT License
3.26k stars 581 forks source link

Copy() changes the names of all of the nodes in the graph #215

Open ed-mw opened 4 years ago

ed-mw commented 4 years ago

When I instantiate a graph using Copy(), the new graph contains all of the nodes - but their names are changed (i.e. Original Name(Clone)" instead of "Original Name"). How can I avoid this?

Originally posted by @eddieray in https://github.com/Siccity/xNode/issues/213#issuecomment-561205681

ed-mw commented 4 years ago

This seems to fix the issue...

diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs
index 6a0cead..a20b8a7 100644
--- a/Scripts/NodeGraph.cs
+++ b/Scripts/NodeGraph.cs
@@ -62,6 +62,7 @@ namespace XNode {
                 if (nodes[i] == null) continue;
                 Node.graphHotfix = graph;
                 Node node = Instantiate(nodes[i]) as Node;
+                node.name = nodes[i].name;
                 node.graph = graph;
                 graph.nodes[i] = node;
             }