diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs
index 7ef961c..6cea69c 100644
--- a/Scripts/Editor/NodeEditorAction.cs
+++ b/Scripts/Editor/NodeEditorAction.cs
@@ -302,7 +302,7 @@ namespace XNodeEditor {
foreach (UnityEngine.Object item in Selection.objects) {
if (item is XNode.Node) {
XNode.Node node = item as XNode.Node;
- graph.RemoveNode(node);
+ graphEditor.RemoveNode(node);
}
}
}
@@ -324,7 +324,7 @@ namespace XNodeEditor {
if (Selection.objects[i] is XNode.Node) {
XNode.Node srcNode = Selection.objects[i] as XNode.Node;
if (srcNode.graph != graph) continue; // ignore nodes selected in another graph
- XNode.Node newNode = graph.CopyNode(srcNode);
+ XNode.Node newNode = graphEditor.CopyNode(srcNode);
substitutes.Add(srcNode, newNode);
newNode.position = srcNode.position + new Vector2(30, 30);
newNodes[i] = newNode;
diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs
index 2a8f43c..5025aaa 100644
--- a/Scripts/Editor/NodeGraphEditor.cs
+++ b/Scripts/Editor/NodeGraphEditor.cs
@@ -39,6 +39,22 @@ namespace XNodeEditor {
return NodeEditorPreferences.GetTypeColor(type);
}
+ /// Creates a copy of the original node in the graph
+ public XNode.Node CopyNode(XNode.Node original) {
+ XNode.Node node = target.CopyNode(original);
+ node.name = original.name;
+ AssetDatabase.AddObjectToAsset(node, target);
+ AssetDatabase.SaveAssets();
+ return node;
+ }
+
+ /// Safely remove a node and all its connections.
+ public void RemoveNode(XNode.Node node) {
+ UnityEngine.Object.DestroyImmediate(node, true);
+ target.RemoveNode(node);
+ AssetDatabase.SaveAssets();
+ }
+
[AttributeUsage(AttributeTargets.Class)]
public class CustomNodeGraphEditorAttribute : Attribute,
XNodeEditor.Internal.NodeEditorBase.INodeEditorAttrib {
diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs
index 05b865b..09010dc 100644
--- a/Scripts/NodeGraph.cs
+++ b/Scripts/NodeGraph.cs
@@ -28,13 +28,6 @@ namespace XNode {
public virtual Node CopyNode(Node original) {
Node node = ScriptableObject.Instantiate(original);
node.ClearConnections();
-#if UNITY_EDITOR
- if (!Application.isPlaying) {
- UnityEditor.AssetDatabase.AddObjectToAsset(node, this);
- UnityEditor.AssetDatabase.SaveAssets();
- node.name = UnityEditor.ObjectNames.NicifyVariableName(node.name);
- }
-#endif
nodes.Add(node);
node.graph = this;
return node;
@@ -44,12 +37,6 @@ namespace XNode {
///
public void RemoveNode(Node node) {
node.ClearConnections();
-#if UNITY_EDITOR
- if (!Application.isPlaying) {
- DestroyImmediate(node, true);
- UnityEditor.AssetDatabase.SaveAssets();
- }
-#endif
nodes.Remove(node);
}