diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index b47c30d8894..06bcc6e52fe 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -329,17 +329,21 @@ bool EditorProperty::is_read_only() const { return read_only; } -Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property) { +Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid) { if (p_object->has_method("property_can_revert") && p_object->call("property_can_revert", p_property)) { + if (r_is_valid) { + *r_is_valid = true; + } return p_object->call("property_get_revert", p_property); } - return PropertyUtils::get_property_default_value(p_object, p_property); + return PropertyUtils::get_property_default_value(p_object, p_property, r_is_valid); } bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { - Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property); - if (revert_value.get_type() == Variant::NIL) { + bool is_valid_revert = false; + Variant revert_value = EditorPropertyRevert::get_property_revert_value(p_object, p_property, &is_valid_revert); + if (!is_valid_revert) { return false; } Variant current_value = p_object->get(p_property); @@ -522,7 +526,9 @@ void EditorProperty::_gui_input(const Ref &p_event) { } if (revert_rect.has_point(mb->get_position())) { - Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property); + bool is_valid_revert = false; + Variant revert_value = EditorPropertyRevert::get_property_revert_value(object, property, &is_valid_revert); + ERR_FAIL_COND(!is_valid_revert); emit_changed(property, revert_value); update_property(); } @@ -611,8 +617,9 @@ static bool _is_value_potential_override(Node *p_node, const String &p_property) if (states_stack.size()) { return true; } else { + bool is_valid_default = false; bool is_class_default = false; - PropertyUtils::get_property_default_value(p_node, p_property, &states_stack, false, nullptr, &is_class_default); + PropertyUtils::get_property_default_value(p_node, p_property, &is_valid_default, &states_stack, false, nullptr, &is_class_default); return !is_class_default; } } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 3d3f8cbdce1..a963efa4500 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -42,7 +42,7 @@ public: static bool get_instanced_node_original_property(Node *p_node, const StringName &p_prop, Variant &value, bool p_check_class_default = true); static bool is_node_property_different(Node *p_node, const Variant &p_current, const Variant &p_orig); static bool is_property_value_different(const Variant &p_a, const Variant &p_b); - static Variant get_property_revert_value(Object *p_object, const StringName &p_property); + static Variant get_property_revert_value(Object *p_object, const StringName &p_property, bool *r_is_valid); static bool can_property_revert(Object *p_object, const StringName &p_property); }; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 38f5aae7e57..37aed5e54b0 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -3106,8 +3106,9 @@ void SceneTreeDock::_create_remap_for_node(Node *p_node, Map &r_remap) states_stack_ready = true; } - Variant orig = PropertyUtils::get_property_default_value(p_node, E->get().name, &states_stack); - if (!PropertyUtils::is_property_value_different(v, orig)) { + bool is_valid_default = false; + Variant orig = PropertyUtils::get_property_default_value(p_node, E->get().name, &is_valid_default, &states_stack); + if (is_valid_default && !PropertyUtils::is_property_value_different(v, orig)) { continue; } diff --git a/scene/property_utils.cpp b/scene/property_utils.cpp index 5d3c08d7f42..bed00e72e3d 100644 --- a/scene/property_utils.cpp +++ b/scene/property_utils.cpp @@ -48,7 +48,7 @@ bool PropertyUtils::is_property_value_different(const Variant &p_a, const Varian } } -Variant PropertyUtils::get_property_default_value(const Object *p_object, const StringName &p_property, const Vector *p_states_stack_cache, bool p_update_exports, const Node *p_owner, bool *r_is_class_default) { +Variant PropertyUtils::get_property_default_value(const Object *p_object, const StringName &p_property, bool *r_is_valid, const Vector *p_states_stack_cache, bool p_update_exports, const Node *p_owner, bool *r_is_class_default) { // This function obeys the way property values are set when an object is instantiated, // which is the following (the latter wins): // 1. Default value from builtin class @@ -58,6 +58,9 @@ Variant PropertyUtils::get_property_default_value(const Object *p_object, const if (r_is_class_default) { *r_is_class_default = false; } + if (r_is_valid) { + *r_is_valid = false; + } Ref