### 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 (ap) {
			List<StringName> names;
			ap->get_animation_list(&names);
			for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
				animations_menu->add_icon_item(get_theme_icon("Animation", "EditorIcons"), E->get());
				animations_to_add.push_back(E->get());
			}
		}
	}
	for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
		String name = String(E->get()).replace_first("AnimationNode", "");
		if (name == "Animation" || name == "StartState" || name == "EndState") {
			continue; 
		}
		int idx = menu->get_item_count();
		menu->add_item(vformat(TTR("Add %s"), name), idx);
		menu->set_item_metadata(idx, E->get());
	}
	Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
	if (clipb.is_valid()) {
		menu->add_separator();
		menu->add_item(TTR("Paste"), MENU_PASTE);
	}
	menu->add_separator();
	menu->add_item(TTR("Load..."), MENU_LOAD_FILE);
	menu->set_position(state_machine_draw->get_screen_transform().xform(p_position));
	menu->popup();
	add_node_pos = p_position / EDSCALE + state_machine->get_graph_offset();
}
void AnimationNodeStateMachineEditor::_open_connect_menu(const Vector2 &p_position) {