Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix misconfigured node.graph reference during node instantiation and …
…graph cloning (#85)

* Attempting to fix #81 in a cleaner way. Still not perfect

* Fixed setting to null during OnEnable

* Fixed spelling
  • Loading branch information
Siccity committed Dec 11, 2018
1 parent 6c1af6f commit a0eee5b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Scripts/Node.cs
Expand Up @@ -60,7 +60,13 @@ public enum ConnectionType {
/// <summary> It is recommended not to modify these at hand. Instead, see <see cref="InputAttribute"/> and <see cref="OutputAttribute"/> </summary>
[SerializeField] private NodePortDictionary ports = new NodePortDictionary();

/// <summary> Used during node instantiation to fix null/misconfigured graph during OnEnable/Init. Set it before instantiating a node. Will automatically be unset during OnEnable </summary>
public static NodeGraph graphHotfix;


protected void OnEnable() {
if (graphHotfix != null) graph = graphHotfix;
graphHotfix = null;
UpdateStaticPorts();
Init();
}
Expand Down Expand Up @@ -308,4 +314,4 @@ public class NodeWidth : Attribute {
}
}
}
}
}
7 changes: 5 additions & 2 deletions Scripts/NodeGraph.cs
Expand Up @@ -18,18 +18,20 @@ public abstract class NodeGraph : ScriptableObject {

/// <summary> Add a node to the graph by type </summary>
public virtual Node AddNode(Type type) {
Node.graphHotfix = this;
Node node = ScriptableObject.CreateInstance(type) as Node;
nodes.Add(node);
node.graph = this;
nodes.Add(node);
return node;
}

/// <summary> Creates a copy of the original node in the graph </summary>
public virtual Node CopyNode(Node original) {
Node.graphHotfix = this;
Node node = ScriptableObject.Instantiate(original);
node.graph = this;
node.ClearConnections();
nodes.Add(node);
node.graph = this;
return node;
}

Expand Down Expand Up @@ -58,6 +60,7 @@ public abstract class NodeGraph : ScriptableObject {
// Instantiate all nodes inside the graph
for (int i = 0; i < nodes.Count; i++) {
if (nodes[i] == null) continue;
Node.graphHotfix = graph;
Node node = Instantiate(nodes[i]) as Node;
node.graph = graph;
graph.nodes[i] = node;
Expand Down

0 comments on commit a0eee5b

Please sign in to comment.