diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs index 32310d2..e9fe75f 100644 --- a/Scripts/NodeGraph.cs +++ b/Scripts/NodeGraph.cs @@ -38,10 +38,16 @@ namespace XNode { public void RemoveNode(Node node) { node.ClearConnections(); nodes.Remove(node); + if (Application.isPlaying) Destroy(node); } /// Remove all nodes and connections from the graph public void Clear() { + if (Application.isPlaying) { + for (int i = 0; i < nodes.Count; i++) { + Destroy(nodes[i]); + } + } nodes.Clear(); } @@ -67,5 +73,10 @@ namespace XNode { return graph; } + + private void OnDestroy() { + // Remove all nodes prior to graph destruction + Clear(); + } } } \ No newline at end of file