### 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 (!selected_nodes.is_empty()) {
		if (!p_nested_action) {
			updating = true;
		}
		EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
		undo_redo->create_action(TTR("Node Removed"));
		for (int i = 0; i < node_rects.size(); i++) {
			if (node_rects[i].node_name == state_machine->start_node || node_rects[i].node_name == state_machine->end_node) {
				continue;
			}
			if (!selected_nodes.has(node_rects[i].node_name)) {
				continue;
			}
			undo_redo->add_do_method(state_machine.ptr(), "remove_node", node_rects[i].node_name);
			undo_redo->add_undo_method(state_machine.ptr(), "add_node", node_rects[i].node_name,
					state_machine->get_node(node_rects[i].node_name),
					state_machine->get_node_position(node_rects[i].node_name));
			for (int j = 0; j < state_machine->get_transition_count(); j++) {
				String from = state_machine->get_transition_from(j);
				String to = state_machine->get_transition_to(j);
				String local_from = from.get_slicec('/', 0);
				String local_to = to.get_slicec('/', 0);
				if (local_from == node_rects[i].node_name || local_to == node_rects[i].node_name) {
					undo_redo->add_undo_method(state_machine.ptr(), "add_transition", from, to, state_machine->get_transition(j));
				}
			}
		}