From 69ee12169ddb9db88cba52e5f88c9476628844eb Mon Sep 17 00:00:00 2001 From: Thor Brigsted Date: Sat, 14 Apr 2018 22:49:16 +0200 Subject: [PATCH] Destroy nodes on graph destruction #30 --- Scripts/NodeGraph.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) 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