1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-04 12:00:25 +00:00

Merge pull request #109049 from ryevdokimov/deprecate-script-add-root-node

Relocate `add_root_node` method to `EditorInterface` from `EditorScript` and deprecate old method
This commit is contained in:
Thaddeus Crews
2025-10-01 13:12:45 -05:00
5 changed files with 38 additions and 25 deletions

View File

@@ -38,30 +38,8 @@
#include "scene/resources/packed_scene.h"
void EditorScript::add_root_node(Node *p_node) {
if (!EditorNode::get_singleton()) {
EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("Write your logic in the _run() method."));
return;
}
if (EditorNode::get_singleton()->get_edited_scene()) {
EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("The current scene already has a root node."));
return;
}
const String &scene_path = p_node->get_scene_file_path();
if (!scene_path.is_empty()) {
Ref<PackedScene> scene = ResourceLoader::load(scene_path);
if (scene.is_valid()) {
memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache.
p_node->set_scene_inherited_state(scene->get_state());
p_node->set_scene_file_path(String());
}
}
EditorNode::get_singleton()->set_edited_scene(p_node);
EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id());
EditorSceneTabs::get_singleton()->update_scene_tabs();
WARN_DEPRECATED_MSG("EditorScript::add_root_node is deprecated. Use EditorInterface::add_root_node instead.");
EditorInterface::get_singleton()->add_root_node(p_node);
}
Node *EditorScript::get_scene() const {