diff --git a/Scripts/Node.cs b/Scripts/Node.cs
index 17e4d4f..488971a 100644
--- a/Scripts/Node.cs
+++ b/Scripts/Node.cs
@@ -134,10 +134,14 @@ namespace XNode {
}
#endregion
- /// Called whenever a connection is being made between two s
+ /// Called after a connection between two s is created
/// Output Input
public virtual void OnCreateConnection(NodePort from, NodePort to) { }
+ /// Called after a connection is removed from this port
+ /// Output Input
+ public virtual void OnRemoveConnection(NodePort port) { }
+
/// Disconnect everything from this node
public void ClearConnections() {
foreach (NodePort port in Ports) port.ClearConnections();
diff --git a/Scripts/NodePort.cs b/Scripts/NodePort.cs
index c26ad90..3aba9ed 100644
--- a/Scripts/NodePort.cs
+++ b/Scripts/NodePort.cs
@@ -204,16 +204,22 @@ namespace XNode {
return false;
}
+ /// Disconnect this port from another port
public void Disconnect(NodePort port) {
+ NodePort from = direction == IO.Input ? port : this;
+ NodePort to = direction == IO.Input ? this : port;
+ // Remove this ports connection to the other
for (int i = connections.Count - 1; i >= 0; i--) {
- //Remove matching ports.
if (connections[i].Port == port) {
connections.RemoveAt(i);
+ node.OnRemoveConnection(this);
}
}
+ // Remove the other ports connection to this port
for (int i = 0; i < port.connections.Count; i++) {
if (port.connections[i].Port == this) {
port.connections.RemoveAt(i);
+ port.node.OnRemoveConnection(port);
}
}
}