### Godot version

v4.1.1-stable_mono_win64

### System information

Windows 11

### Issue description

I removed the node to replace it with another, but when I change the path in the code, the engine crashes for me.

### Steps to reproduce

I did a screen recording as it happens:

https://github.com/godotengine/godot/assets/116289408/b2fd2689-8d82-44e8-8e02-be01674842e1



### Minimal reproduction project

[MixApo.zip](https://github.com/godotengine/godot/files/12208403/MixApo.zip)

}
			if (is_in_string(i) == -1 && is_in_comment(i) == -1) {
				break;
			}
		}
	}
	for (int i = p_line + 1; i <= end_line; i++) {
		_set_line_as_hidden(i, true);
	}
	for (int i = 0; i < get_caret_count(); i++) {
		
		if (has_selection(i)) {
			if (_is_line_hidden(get_selection_from_line(i)) && _is_line_hidden(get_selection_to_line(i))) {
				deselect(i);
			} else if (_is_line_hidden(get_selection_from_line(i))) {
				select(p_line, 9999, get_selection_to_line(i), get_selection_to_column(i), i);
			} else if (_is_line_hidden(get_selection_to_line(i))) {
				select(get_selection_from_line(i), get_selection_from_column(i), p_line, 9999, i);
			}
		}
		
		if (_is_line_hidden(get_caret_line(i))) {
			set_caret_line(p_line, false, false, 0, i);
			set_caret_column(get_line(p_line).length(), false, i);
		}
	}
	merge_overlapping_carets();
	queue_redraw();
}
void CodeEdit::unfold_line(int p_line) {