### 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
undo_redo->add_undo_method(this, "_update_graph");
		undo_redo->commit_action();
		updating = false;
		selected_nodes.clear();
		selected_nodes.insert(group_name);
		state_machine_draw->queue_redraw();
		accept_event();
		_update_mode();
	}
}
void AnimationNodeStateMachineEditor::_ungroup_selected_nodes() {
	bool find = false;
	HashSet<StringName> new_selected_nodes;
	for (const StringName &E : selected_nodes) {
		Ref<AnimationNodeStateMachine> group_sm = state_machine->get_node(E);
		if (group_sm.is_valid()) {
			find = true;
			Vector2 group_position = state_machine->get_node_position(E);
			StringName group_name = E;
			List<AnimationNode::ChildNode> nodes;
			group_sm->get_child_nodes(&nodes);
			Vector<NodeUR> nodes_ur;
			Vector<TransitionUR> transitions_ur;
			updating = true;
			EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
			undo_redo->create_action("Ungroup");
			
			for (int i = 0; i < nodes.size(); i++) {
				if (!group_sm->can_edit_node(nodes[i].name)) {
					continue;