From 1de6256401bcd7ee9565497497bd125bf1786755 Mon Sep 17 00:00:00 2001 From: Serhii Snitsaruk Date: Mon, 25 Mar 2024 00:56:08 +0100 Subject: [PATCH] Plan: Don't store unmodified variables in a derived plan Fixes "sticky" old values in a derived plan. --- blackboard/blackboard_plan.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/blackboard/blackboard_plan.cpp b/blackboard/blackboard_plan.cpp index 0e27a2d..d1122f7 100644 --- a/blackboard/blackboard_plan.cpp +++ b/blackboard/blackboard_plan.cpp @@ -16,10 +16,11 @@ bool BlackboardPlan::_set(const StringName &p_name, const Variant &p_value) { // * Editor if (var_map.has(p_name)) { - var_map[p_name].set_value(p_value); + BBVariable &var = var_map[p_name]; + var.set_value(p_value); if (base.is_valid() && p_value == base->get_var(p_name).get_value()) { // When user pressed reset property button in inspector... - var_map[p_name].reset_value_changed(); + var.reset_value_changed(); } return true; } @@ -92,6 +93,12 @@ void BlackboardPlan::_get_property_list(List *p_list) const { p_list->push_back(PropertyInfo(var.get_type(), var_name, var.get_hint(), var.get_hint_string(), PROPERTY_USAGE_EDITOR)); } + if (is_derived() && (!var.is_value_changed() || var.get_value() == base->var_map[var_name].get_value())) { + // Don't store variable if it's not modified in a derived plan. + // Variable is considered modified when it's marked as changed and its value is different from the base plan. + continue; + } + // * Storage p_list->push_back(PropertyInfo(Variant::STRING, "var/" + var_name + "/name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL)); p_list->push_back(PropertyInfo(Variant::INT, "var/" + var_name + "/type", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR | PROPERTY_USAGE_INTERNAL));