### Godot version

41e5f5b0930343ef548a56d553ba20fafd672147

### System information

Windows 10, Vulkan, Intel® Core™ i7-8700K, Nvidia GTX 1080 (471.11)

### Issue description

The editor will crash if you select an AnimationTree node then select another node. This seems to be caused by the edit function assigning a null object via the edit interface, then calling another function which does not appear to be null.

### Steps to reproduce

Create an AnimationTree node then select another node.

### Minimal reproduction project

N/A
if (ansm.is_valid()) {
				bool parent_found = false;
				for (int i = 0; i < parents.size(); i++) {
					if (parents[i] == ansm) {
						path = path.replace_first("/../" + E, "");
						parent_found = true;
						break;
					}
				}
				if (parent_found) {
					end_menu->add_item(E, nodes_to_connect.size());
					nodes_to_connect.push_back(path + "/" + state_machine->end_node);
				} else {
					state_machine_menu->add_item(E, nodes_to_connect.size());
					nodes_to_connect.push_back(path);
				}
				if (_create_submenu(nodes_menu, ansm, E, path, false, parents)) {
					nodes_menu->add_submenu_item(E, E);
					node_added = true;
				}
			} else {
				nodes_menu->add_item(E, nodes_to_connect.size());
				nodes_to_connect.push_back(path);
				node_added = true;
			}
		}
	}
	return node_added;
}
void AnimationNodeStateMachineEditor::_stop_connecting() {