private void CreateNodeInTheOpenedGraph(Type type, Vector2 worldPosition, bool recordUndo, bool saveAssets = false) { Node node = GraphUtils.CreateNode(CurrentGraph, type, worldPosition); if (recordUndo) { RecordUndo("Create " + type.Name); //record undo for the creation of this node } CurrentGraph.Nodes.Add(node); //add the new node reference to the graph's nodes list if (!EditorUtility.IsPersistent(node)) { AssetDatabase.AddObjectToAsset(node, CurrentGraph); //if the node does not have an asset file -> crete it and nest it under the graph asset file } switch (node.NodeType) { case NodeType.General: case NodeType.SubGraph: //AUTO CONNECT the new node TO either the START or ENTER node - if the start or enter nodes are not connected Node startOrEnterNode = CurrentGraph.GetStartOrEnterNode(); if (startOrEnterNode != null && //if we have a start or enter node !startOrEnterNode.OutputSockets[0].IsConnected && //that is NOT connected node.InputSockets != null && //and its inputSockets list is NOT null (sanity check) node.InputSockets.Count > 0) //and it has at least one input socket (again... sanity check) { ConnectSockets(startOrEnterNode.OutputSockets[0], node.InputSockets[0]); //connect the new created node with the Start or Enter node } break; } EditorUtility.SetDirty(node); //mark the new node as dirty CurrentGraph.SetDirty(saveAssets); //set the graph dirty if (recordUndo) { GraphEvent.Send(GraphEvent.EventType.EVENT_NODE_CREATED); //notify the system the a node has been created } SelectNodes(new List <Node> { node }, false, false); //select the newly created node WindowSettings.SetDirty(false); }