public static void CreateConnection(ConnectionPort port1, ConnectionPort port2)
 {
     if (port1 == null || port2 == null)
     {             // Not critical. Happens when undo records are triggered, but it's canvas has been unloaded
         // Debug.LogWarning("Lost reference to Undo SO 'port'!");
         return;
     }
     // Workaround for undo records created in playmode that have being deleted (by Unity) after exiting
     if (port1.body.canvas.nodes.Contains(port1.body) && port2.body.canvas.nodes.Contains(port2.body))
     {
         port1.TryApplyConnection(port2, true);
     }
 }
        public static void ReinstateNode(Node node, List <ConnectionPort> connectedPorts)
        {
            if (node == null)
            {             // Not critical. Happens when undo records are triggered, but it's canvas has been unloaded
                // Debug.LogWarning("Lost reference to Undo SO 'node'!");
                return;
            }
            if (connectedPorts == null)             // Should not happen if node has not been lost
            {
                Debug.LogWarning("Lost reference to Undo SO 'connectedPorts'!");
            }
            node.canvas.nodes.Remove(node);
            node.canvas.nodes.Add(node);
            ConnectionPortManager.UpdateConnectionPorts(node);
            if (connectedPorts != null)
            {
                int portIndex = 0;
                for (int i = 0; i < connectedPorts.Count; i++)
                {
                    if (connectedPorts[i] == null)
                    {                     // 'Decode' null-seperated list
                        portIndex++;
                        continue;
                    }
                    if (node.connectionPorts.Count <= portIndex)
                    {
                        Debug.LogWarning("Misaligned port count in reinstated node!");
                        break;
                    }
                    ConnectionPort port1 = node.connectionPorts[portIndex], port2 = connectedPorts[i];
                    // Workaround for undo records created in playmode that have being deleted (by Unity) after exiting
                    if (port1.body.canvas.nodes.Contains(port1.body) && port2.body.canvas.nodes.Contains(port2.body))
                    {
                        port1.TryApplyConnection(port2, true);
                    }
                }

                if (node.connectionPorts.Count > portIndex)
                {
                    Debug.LogWarning("Misaligned port count in reinstated node!");
                }
            }
        }