### 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 (selected_nodes.size() == 1 && (*selected_nodes.begin() == state_machine->start_node || *selected_nodes.begin() == state_machine->end_node))
			return;
		Ref<AnimationNodeStateMachine> group_sm = memnew(AnimationNodeStateMachine);
		Vector2 group_position;
		Vector<NodeUR> nodes_ur;
		Vector<TransitionUR> transitions_ur;
		int base = 1;
		String base_name = group_sm->get_caption();
		String group_name = base_name;
		while (state_machine->has_node(group_name) && !selected_nodes.has(group_name)) {
			base++;
			group_name = base_name + " " + itos(base);
		}
		updating = true;
		EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
		undo_redo->create_action("Group");
		
		for (const StringName &E : selected_nodes) {
			if (!state_machine->can_edit_node(E)) {