### 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
ERR_FAIL_COND(connecting_to_node == StringName());
	Ref<AnimationNode> node = state_machine->get_node(connecting_to_node);
	Ref<AnimationNodeStateMachine> anodesm = node;
	Ref<AnimationNodeEndState> end_node = node;
	ERR_FAIL_COND(!anodesm.is_valid() && !end_node.is_valid());
	connect_menu->clear();
	state_machine_menu->clear();
	end_menu->clear();
	nodes_to_connect.clear();
	for (int i = connect_menu->get_child_count() - 1; i >= 0; i--) {
		Node *child = connect_menu->get_child(i);
		if (child->is_class("PopupMenu")) {
			connect_menu->remove_child(child);
		}
	}
	connect_menu->reset_size();
	state_machine_menu->reset_size();
	end_menu->reset_size();
	if (anodesm.is_valid()) {
		_create_submenu(connect_menu, anodesm, connecting_to_node, connecting_to_node);
	} else {