MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / add_root_node

Method add_root_node

editor/script/editor_script.cpp:48–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46#include "scene/resources/packed_scene.h"
47
48void 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
75Node *EditorScript::get_scene() const {
76 if (!EditorNode::get_singleton()) {

Callers 3

drop_data_fwMethod · 0.45
_add_sun_to_sceneMethod · 0.45

Calls 14

TTRFunction · 0.85
get_scene_file_pathMethod · 0.80
set_scene_file_pathMethod · 0.80
update_scene_tabsMethod · 0.80
StringClass · 0.50
get_edited_sceneMethod · 0.45
is_emptyMethod · 0.45
is_validMethod · 0.45
instantiateMethod · 0.45

Tested by

no test coverage detected