diff --git a/Scripts/NodeGraph.cs b/Scripts/NodeGraph.cs
index d928f94..ef0a314 100644
--- a/Scripts/NodeGraph.cs
+++ b/Scripts/NodeGraph.cs
@@ -10,6 +10,15 @@ namespace XNode {
/// All nodes in the graph.
/// See:
[SerializeField] public List nodes = new List();
+
+ private void Awake() {
+ List newNodes = new List(nodes.Count);
+ foreach (var node in nodes) {
+ newNodes.Add(Instantiate(node));
+ }
+ nodes.Clear();
+ nodes = newNodes;
+ }
/// Add a node to the graph by type (convenience method - will call the System.Type version)
public T AddNode() where T : Node {
@@ -47,7 +56,8 @@ namespace XNode {
public virtual void Clear() {
if (Application.isPlaying) {
for (int i = 0; i < nodes.Count; i++) {
- Destroy(nodes[i]);
+ if(nodes[i]) //Graph destroy nodes only here, but this check prevent nullref when node was destroyed outside
+ Destroy(nodes[i]);
}
}
nodes.Clear();
@@ -121,4 +131,4 @@ namespace XNode {
}
#endregion
}
-}
\ No newline at end of file
+}