Skip to content

Commit

Permalink
Fix New Viewport Texture in Editor Inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilderin committed Sep 20, 2024
1 parent 0a4aedb commit 92a0fc0
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
12 changes: 9 additions & 3 deletions editor/editor_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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());
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -653,6 +654,8 @@ class EditorInspector : public ScrollContainer {
void set_property_clipboard(const Variant &p_value);
Variant get_property_clipboard() const;

void set_update_tree_paused(bool p_paused);

EditorInspector();
};

Expand Down
33 changes: 33 additions & 0 deletions editor/editor_properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions editor/editor_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion scene/main/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
Expand Down

0 comments on commit 92a0fc0

Please sign in to comment.