Fix New Viewport Texture in Editor Inspector

This commit is contained in:
Hilderin 2024-09-20 10:25:23 -04:00
parent 0a4aedb360
commit 92a0fc088f
5 changed files with 52 additions and 4 deletions

View file

@ -4138,9 +4138,11 @@ void EditorInspector::_notification(int p_what) {
changing++;
if (update_tree_pending) {
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());

View file

@ -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();
};

View file

@ -3122,7 +3122,19 @@ void EditorPropertyResource::_resource_changed(const Ref<Resource> &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<EditorInspector>(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);

View file

@ -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<Resource> &p_resource, const String &p_property);
void _sub_inspector_object_id_selected(int p_id);

View file

@ -167,7 +167,10 @@ Ref<Image> 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.");
}
}