| 46 | #include "scene/resources/packed_scene.h" |
| 47 | |
| 48 | void EditorScript::add_root_node(Node *p_node) { |
| 49 | if (!EditorNode::get_singleton()) { |
| 50 | EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("Write your logic in the _run() method.")); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if (EditorNode::get_singleton()->get_edited_scene()) { |
| 55 | EditorNode::add_io_error("EditorScript::add_root_node: " + TTR("The current scene already has a root node.")); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | const String &scene_path = p_node->get_scene_file_path(); |
| 60 | if (!scene_path.is_empty()) { |
| 61 | Ref<PackedScene> scene = ResourceLoader::load(scene_path); |
| 62 | if (scene.is_valid()) { |
| 63 | memfree(scene->instantiate(PackedScene::GEN_EDIT_STATE_INSTANCE)); // Ensure node cache. |
| 64 | |
| 65 | p_node->set_scene_inherited_state(scene->get_state()); |
| 66 | p_node->set_scene_file_path(String()); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | EditorNode::get_singleton()->set_edited_scene(p_node); |
| 71 | EditorUndoRedoManager::get_singleton()->set_history_as_unsaved(EditorNode::get_editor_data().get_current_edited_scene_history_id()); |
| 72 | EditorSceneTabs::get_singleton()->update_scene_tabs(); |
| 73 | } |
| 74 | |
| 75 | Node *EditorScript::get_scene() const { |
| 76 | if (!EditorNode::get_singleton()) { |
no test coverage detected