Skip to content

Commit

Permalink
Add remove root node method to EditorScript
Browse files Browse the repository at this point in the history
  • Loading branch information
ryevdokimov committed Jun 29, 2024
1 parent 811ce36 commit 0ef2445
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/classes/EditorScript.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,11 @@
Returns the edited (current) scene's root [Node]. Equivalent of [method EditorInterface.get_edited_scene_root].
</description>
</method>
<method name="remove_root_node">
<return type="void" />
<description>
Removes the currently edited scene.
</description>
</method>
</methods>
</class>
7 changes: 7 additions & 0 deletions editor/editor_script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ void EditorScript::add_root_node(Node *p_node) {
EditorSceneTabs::get_singleton()->update_scene_tabs();
}

void EditorScript::remove_root_node() {
EditorNode::get_singleton()->set_edited_scene(nullptr);
EditorUndoRedoManager::get_singleton()->set_history_as_saved(EditorNode::get_editor_data().get_current_edited_scene_history_id());
EditorSceneTabs::get_singleton()->update_scene_tabs();
}

Node *EditorScript::get_scene() const {
if (!EditorNode::get_singleton()) {
EditorNode::add_io_error("EditorScript::get_scene: " + TTR("Write your logic in the _run() method."));
Expand All @@ -83,6 +89,7 @@ void EditorScript::run() {

void EditorScript::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorScript::add_root_node);
ClassDB::bind_method(D_METHOD("remove_root_node"), &EditorScript::remove_root_node);
ClassDB::bind_method(D_METHOD("get_scene"), &EditorScript::get_scene);
ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorScript::get_editor_interface);

Expand Down
1 change: 1 addition & 0 deletions editor/editor_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class EditorScript : public RefCounted {

public:
void add_root_node(Node *p_node);
void remove_root_node();
Node *get_scene() const;
EditorInterface *get_editor_interface() const;

Expand Down

0 comments on commit 0ef2445

Please sign in to comment.