diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index a215662f167..48deef0f9ff 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -4138,9 +4138,11 @@ void EditorInspector::_notification(int p_what) { changing++; if (update_tree_pending) { - update_tree(); - update_tree_pending = false; - pending.clear(); + if (!update_tree_paused) { + update_tree(); + update_tree_pending = false; + pending.clear(); + } } else { while (pending.size()) { @@ -4247,6 +4249,10 @@ Variant EditorInspector::get_property_clipboard() const { return property_clipboard; } +void EditorInspector::set_update_tree_paused(bool p_paused) { + update_tree_paused = p_paused; +} + void EditorInspector::_show_add_meta_dialog() { if (!add_meta_dialog) { add_meta_dialog = memnew(AddMetadataDialog()); diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 14b6ff0907a..d81a163d890 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -520,6 +520,7 @@ class EditorInspector : public ScrollContainer { float refresh_countdown; bool update_tree_pending = false; + bool update_tree_paused = false; StringName _prop_edited; StringName property_selected; int property_focusable; @@ -653,6 +654,8 @@ public: void set_property_clipboard(const Variant &p_value); Variant get_property_clipboard() const; + void set_update_tree_paused(bool p_paused); + EditorInspector(); }; diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 0fb57ce40e7..b90ca41a7d5 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -3122,7 +3122,19 @@ void EditorPropertyResource::_resource_changed(const Ref &p_resource) add_child(scene_tree); scene_tree->connect("selected", callable_mp(this, &EditorPropertyResource::_viewport_selected)); + scene_tree->connect("visibility_changed", callable_mp(this, &EditorPropertyResource::_scene_tree_visibility_changed)); } + + // We need to pause the inspector to update it's tree to prevent the + // recreation of the current EditorPropertyResource instance which contains + // the scene tree dialog. EditorInspector recreates all the controls on update tree + // and the update tree is triggered by the signal property_list_changed in BaseMaterial3D + // when the ViewportTexture is set on the current propecty. + EditorInspector *parent_inspector = _get_parent_inspector(); + if (parent_inspector) { + parent_inspector->set_update_tree_paused(true); + } + scene_tree->popup_scenetree_dialog(); } } @@ -3194,6 +3206,27 @@ void EditorPropertyResource::_viewport_selected(const NodePath &p_path) { update_property(); } +EditorInspector *EditorPropertyResource::_get_parent_inspector() { + Node *parent = get_parent(); + while (parent) { + EditorInspector *inspector = Object::cast_to(parent); + if (inspector) { + return inspector; + } + parent = parent->get_parent(); + } + return nullptr; +} + +void EditorPropertyResource::_scene_tree_visibility_changed() { + if (!scene_tree->is_visible()) { + EditorInspector *parent_inspector = _get_parent_inspector(); + if (parent_inspector) { + parent_inspector->set_update_tree_paused(false); + } + } +} + void EditorPropertyResource::setup(Object *p_object, const String &p_path, const String &p_base_type) { if (resource_picker) { memdelete(resource_picker); diff --git a/editor/editor_properties.h b/editor/editor_properties.h index 2ec78cdb448..1982573b137 100644 --- a/editor/editor_properties.h +++ b/editor/editor_properties.h @@ -677,6 +677,9 @@ class EditorPropertyResource : public EditorProperty { void _viewport_selected(const NodePath &p_path); + EditorInspector *_get_parent_inspector(); + void _scene_tree_visibility_changed(); + void _sub_inspector_property_keyed(const String &p_property, const Variant &p_value, bool p_advance); void _sub_inspector_resource_selected(const Ref &p_resource, const String &p_property); void _sub_inspector_object_id_selected(int p_id); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index acf4f676731..771be992d96 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -167,7 +167,10 @@ Ref ViewportTexture::get_image() const { } void ViewportTexture::_err_print_viewport_not_set() const { - if (!vp_pending && !vp_changed) { + // Removing this error while in the editor to prevent printing this error + // while creating the new ViewportTexture. When creating a new ViewportTexture in the editor, + // it's normal that the vp is not initialized. + if (!vp_pending && !vp_changed && !Engine::get_singleton()->is_editor_hint()) { ERR_PRINT("Viewport Texture must be set to use it."); } }