Repository: godotengine/godot
File: editor/scene_tree_dock.cpp (C++)

Code before:
		undo_redo->add_undo_method(edited_scene, "set_owner", edited_scene->get_owner());
		undo_redo->add_undo_method(scene_tree, "update_tree");
		undo_redo->add_undo_reference(edited_scene);
	} else {
		for (const Node *E : remove_list) {
			// `move_child` + `get_index` doesn't really work for internal nodes.
			ERR_FAIL_COND_MSG(E->get_internal_mode() != INTERNAL_MODE_DISABLED, "Trying to remove internal node, this is not supported.");
		}
		if (delete_tracks_checkbox->is_pressed() || p_cut) {
			remove_list.sort_custom<Node::Comparator>(); // Sort nodes to keep positions.
			HashMap<Node *, NodePath> path_renames;

			//delete from animation
			for (Node *n : remove_list) {
				if (!n->is_inside_tree() || !n->get_parent()) {
					continue;
				}

				fill_path_renames(n, nullptr, &path_renames);
			}

			perform_node_renames(nullptr, &path_renames);
		}

		//delete for read
		for (Node *n : remove_list) {
			if (!n->is_inside_tree() || !n->get_parent()) {
				continue;
			}

			List<Node *> owned;
			n->get_owned_by(n->get_owner(), &owned);
			Array owners;
			for (Node *F : owned) {
				owners.push_back(F);
			}

			undo_redo->add_do_method(n->get_parent(), "remove_child", n);
			undo_redo->add_undo_method(n->get_parent(), "add_child", n, true);
			undo_redo->add_undo_method(n->get_parent(), "move_child", n, n->get_index(false));
			if (AnimationPlayerEditor::get_singleton()->get_track_editor()->get_root() == n) {
				undo_redo->add_undo_method(AnimationPlayerEditor::get_singleton()->get_track_editor(), "set_root", n);
			}
			undo_redo->add_undo_method(this, "_set_owners", edited_scene, owners);
			undo_redo->add_undo_reference(n);

			EditorDebuggerNode *ed = EditorDebuggerNode::get_singleton();
			undo_redo->add_do_method(ed, "live_debug_remove_and_keep_node", edited_scene->get_path_to(n), n->get_instance_id());
			undo_redo->add_undo_method(ed, "live_debug_restore_node", n->get_instance_id(), edited_scene->get_path_to(n->get_parent()), n->get_index(false));
		}
	}

Review comment (suggestion):
```suggestion
		if (!owned_nodes_array.is_empty()) {
```

Code after:
		Node3D *node_3d = Object::cast_to<Node3D>(node);
		if (node_3d) {
			node_3d->set_transform(p_transforms[i]);
		} else {
			Node2D *node_2d = Object::cast_to<Node2D>(node);
			if (node_2d) {
				node_2d->set_transform(p_transforms[i]);
			}
		}

		for (Node *F : owned) {
			F->set_owner(p_owner);
		}
	}
}

void SceneTreeDock::_toggle_editable_children(Node *p_node) {
	if (!p_node) {
		return;
	}

	EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();

	undo_redo->create_action(TTR("Toggle Editable Children"));

	bool editable = !EditorNode::get_singleton()->get_edited_scene()->is_editable_instance(p_node);

	undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_editable_instance", p_node, !editable);
	undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_editable_instance", p_node, editable);

	if (editable) {
		bool original_scene_instance_load_placeholder = p_node->get_scene_instance_load_placeholder();

		undo_redo->add_undo_method(p_node, "set_scene_instance_load_placeholder", original_scene_instance_load_placeholder);
		undo_redo->add_do_method(p_node, "set_scene_instance_load_placeholder", false);
	} else {
		List<Node *> owned;
		p_node->get_owned_by(edited_scene, &owned);

		// Get the original paths, transforms, and names for undo.
		Array owned_nodes_array;
		Array paths_array;
		Array transform_array;
		Array name_array;

		for (Node *owned_node : owned) {
			if (owned_node != p_node && owned_node != edited_scene && owned_node->get_owner() == edited_scene && owned_node->get_parent()->get_owner() != edited_scene) {
				owned_nodes_array.push_back(owned_node);
				paths_array.push_back(p_node->get_path_to(owned_node->get_parent()));
				name_array.push_back(owned_node->get_name());
				Node3D *node_3d = Object::cast_to<Node3D>(owned_node);