### 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
file_loaded = ResourceLoader::load(p_file);
	if (file_loaded.is_valid()) {
		_add_menu_type(MENU_LOAD_FILE_CONFIRM);
	} else {
		EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only animation nodes are allowed."));
	}
}
void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) {
	String base_name;
	Ref<AnimationRootNode> node;
	if (p_index == MENU_LOAD_FILE) {
		open_file->clear_filters();
		List<String> filters;
		ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters);
		for (const String &E : filters) {
			open_file->add_filter("*." + E);
		}
		open_file->popup_file_dialog();
		return;
	} else if (p_index == MENU_LOAD_FILE_CONFIRM) {
		node = file_loaded;
		file_loaded.unref();
	} else if (p_index == MENU_PASTE) {
		node = EditorSettings::get_singleton()->get_resource_clipboard();
	} else {
		String type = menu->get_item_metadata(p_index);
		Object *obj = ClassDB::instantiate(type);
		ERR_FAIL_COND(!obj);