### 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
Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(i);
			if (!from_selected) {
				from = "../" + old_from;
			}
			if (!to_selected) {
				to = "../" + old_to;
			}
			TransitionUR new_tr;
			new_tr.new_from = from;
			new_tr.new_to = to;
			new_tr.old_from = old_from;
			new_tr.old_to = old_to;
			new_tr.transition = tr;
			transitions_ur.push_back(new_tr);
		}
		for (int i = 0; i < nodes_ur.size(); i++) {
			undo_redo->add_do_method(state_machine.ptr(), "remove_node", nodes_ur[i].name);
			undo_redo->add_undo_method(group_sm.ptr(), "remove_node", nodes_ur[i].name);
		}
		undo_redo->add_do_method(state_machine.ptr(), "add_node", group_name, group_sm, group_position / nodes_ur.size());
		undo_redo->add_undo_method(state_machine.ptr(), "remove_node", group_name);
		for (int i = 0; i < nodes_ur.size(); i++) {
			undo_redo->add_do_method(group_sm.ptr(), "add_node", nodes_ur[i].name, nodes_ur[i].node, nodes_ur[i].position);
			undo_redo->add_undo_method(state_machine.ptr(), "add_node", nodes_ur[i].name, nodes_ur[i].node, nodes_ur[i].position);
		}
		for (int i = 0; i < transitions_ur.size(); i++) {
			undo_redo->add_do_method(group_sm.ptr(), "add_transition", transitions_ur[i].new_from, transitions_ur[i].new_to, transitions_ur[i].transition);
			undo_redo->add_undo_method(state_machine.ptr(), "add_transition", transitions_ur[i].old_from, transitions_ur[i].old_to, transitions_ur[i].transition);
		}
		undo_redo->add_do_method(this, "_update_graph");