From 9ca798957d5616d40ef59be6cd05de22881de3a8 Mon Sep 17 00:00:00 2001 From: Carlos Gonzalez Diaz Date: Tue, 4 Oct 2022 13:19:44 +0100 Subject: [PATCH] Update NodeGraphEditor.cs - Handled null nodes coming out of AddNode() both in CreateNode() and AddContextMenuItems() --- Scripts/Editor/NodeGraphEditor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/NodeGraphEditor.cs b/Scripts/Editor/NodeGraphEditor.cs index 191d10b..60b0cdb 100644 --- a/Scripts/Editor/NodeGraphEditor.cs +++ b/Scripts/Editor/NodeGraphEditor.cs @@ -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);