Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Clear inspector when object was invalidated

kobewi9fc84cbc7d75
diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp
index 58fd698114c..96d332a7932 100644
--- a/editor/editor_data.cpp
+++ b/editor/editor_data.cpp
@@ -37,6 +37,7 @@
#include "core/object/callable_mp.h"
#include "core/object/class_db.h"
#include "core/os/time.h"
+#include "editor/docks/inspector_dock.h"
#include "editor/docks/scene_tree_dock.h"
#include "editor/editor_node.h"
#include "editor/editor_undo_redo_manager.h"
@@ -690,6 +691,8 @@ void EditorData::remove_scene(int p_idx) {
undo_redo_manager->discard_history(edited_scene[p_idx].history_id);
}
edited_scene.remove_at(p_idx);
+ // Removing scene also removes its editing history, which might invalidate the edited object.
+ InspectorDock::get_inspector_singleton()->cleanup_object();
}
void EditorData::set_scene_root(int p_idx, Node *p_root) {
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index b31b17a7669..c4b00f5e8c6 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -5124,6 +5124,10 @@ Error EditorNode::open_scene(const String &p_scene, bool p_ignore_broken_deps, b
ERR_FAIL_NULL_V(new_scene, ERR_BUG);
_set_current_scene_nocheck(current_scene_idx, ignore_state);
+ if (editor_data.get_edited_scene_count() == 1) {
+ // When opening the first scene, the [empty] scene history is discarded, which may invalidate inspected object.
+ InspectorDock::get_inspector_singleton()->cleanup_object();
+ }
// When editor plugins load in, they might use node transforms during their own setup, so make sure they're up to date.
get_tree()->flush_transform_notifications();
diff --git a/editor/inspector/editor_inspector.cpp b/editor/inspector/editor_inspector.cpp
index 473da5af76e..26dac7b5510 100644
--- a/editor/inspector/editor_inspector.cpp
+++ b/editor/inspector/editor_inspector.cpp
@@ -5470,6 +5470,12 @@ Object *EditorInspector::get_next_edited_object() {
return next_object;
}
+void EditorInspector::cleanup_object() {
+ if (!ObjectDB::get_instance(edited_object_id)) {
+ _clear();
+ }
+}
+
void EditorInspector::edit(Object *p_object) {
Object *object = ObjectDB::get_instance(edited_object_id);
if (object == p_object) {
diff --git a/editor/inspector/editor_inspector.h b/editor/inspector/editor_inspector.h
index 52507955438..397a4c524c3 100644
--- a/editor/inspector/editor_inspector.h
+++ b/editor/inspector/editor_inspector.h
@@ -946,6 +946,7 @@ public:
void edit(Object *p_object);
Object *get_edited_object();
Object *get_next_edited_object();
+ void cleanup_object();
void set_keying(bool p_active);
void set_read_only(bool p_read_only);