### 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
}
			for (int i = 0; i < transitions_ur.size(); i++) {
				if (transitions_ur[i].old_from != state_machine->start_node && transitions_ur[i].old_to != state_machine->end_node) {
					undo_redo->add_do_method(state_machine.ptr(), "add_transition", transitions_ur[i].new_from, transitions_ur[i].new_to, transitions_ur[i].transition);
				}
				undo_redo->add_undo_method(group_sm.ptr(), "add_transition", transitions_ur[i].old_from, transitions_ur[i].old_to, transitions_ur[i].transition);
			}
			for (int i = 0; i < state_machine->get_transition_count(); i++) {
				String from = state_machine->get_transition_from(i);
				String to = state_machine->get_transition_to(i);
				Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(i);
				if (from == group_name || to == group_name) {
					undo_redo->add_undo_method(state_machine.ptr(), "add_transition", from, to, tr);
				}
			}
			undo_redo->add_do_method(this, "_update_graph");
			undo_redo->add_undo_method(this, "_update_graph");
			undo_redo->commit_action();
			updating = false;
		}
	}
	if (find) {
		selected_nodes = new_selected_nodes;
		selected_node = StringName();
		state_machine_draw->queue_redraw();
		accept_event();
		_update_mode();
	}
}
void AnimationNodeStateMachineEditor::_open_menu(const Vector2 &p_position) {