1
0
mirror of https://github.com/Siccity/xNode.git synced 2025-12-20 01:06:01 +08:00

Merge pull request #357 from carlotes247/master

Update NodeGraphEditor.cs to handle null nodes coming out of AddNode() both in CreateNode() and AddContextMenuItems()
This commit is contained in:
Thor Brigsted 2022-10-04 15:14:02 +02:00 committed by GitHub
commit 7863679da6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,7 +103,7 @@ namespace XNodeEditor {
if (disallowed) menu.AddItem(new GUIContent(path), false, null);
else menu.AddItem(new GUIContent(path), false, () => {
XNode.Node node = CreateNode(type, pos);
NodeEditorWindow.current.AutoConnect(node);
if (node != null) NodeEditorWindow.current.AutoConnect(node); // handle null nodes to avoid nullref exceptions
});
}
menu.AddSeparator("");
@ -213,6 +213,7 @@ namespace XNodeEditor {
public virtual XNode.Node CreateNode(Type type, Vector2 position) {
Undo.RecordObject(target, "Create Node");
XNode.Node node = target.AddNode(type);
if (node == null) return null; // handle null nodes to avoid nullref exceptions
Undo.RegisterCreatedObjectUndo(node, "Create Node");
node.position = position;
if (node.name == null || node.name.Trim() == "") node.name = NodeEditorUtilities.NodeDefaultName(type);