diff --git a/Scripts/Editor/NodeEditorAction.cs b/Scripts/Editor/NodeEditorAction.cs index 95b4600..f9ff7ee 100644 --- a/Scripts/Editor/NodeEditorAction.cs +++ b/Scripts/Editor/NodeEditorAction.cs @@ -69,6 +69,7 @@ public partial class NodeEditorWindow { if (hoveredPort.IsOutput) { draggedOutput = hoveredPort; } else { + hoveredPort.VerifyConnections(); if (hoveredPort.IsConnected) { NodePort output = hoveredPort.Connection; hoveredPort.Disconnect(output); diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs index 0afdb11..c3b7023 100644 --- a/Scripts/NodePort.cs +++ b/Scripts/NodePort.cs @@ -46,12 +46,11 @@ public class NodePort { /// Checks all connections for invalid references, and removes them. public void VerifyConnections() { - for (int i = 0; i < connections.Count; i++) { + for (int i = connections.Count-1; i >= 0; i--) { if (connections[i].node != null && !string.IsNullOrEmpty(connections[i].fieldName) && connections[i].node.GetPortByFieldName(connections[i].fieldName) != null) continue; - Debug.LogWarning("Removed invalid connection"); connections.RemoveAt(i); } } @@ -97,7 +96,8 @@ public class NodePort { } public void Disconnect(NodePort port) { - for (int i = 0; i < connections.Count; i++) { + for (int i = connections.Count - 1; i >= 0; i--) { + //Remove matching ports. if (connections[i].Port == port) { connections.RemoveAt(i); } @@ -128,7 +128,9 @@ public class NodePort { fieldName = port.fieldName; } + /// Returns the port that this points to private NodePort GetPort() { + if (node == null || string.IsNullOrEmpty(fieldName)) return null; for (int i = 0; i < node.OutputCount; i++) { if (node.outputs[i].fieldName == fieldName) return node.outputs[i];