Fix crash upon adding variable in the plan editor with empty default name

Also default to float when expected type is not specified.
This commit is contained in:
Serhii Snitsaruk 2024-05-17 11:08:58 +02:00
parent dc77ecd2b2
commit b54f3696ff
No known key found for this signature in database
GPG Key ID: A965EF8799FFEC2D
2 changed files with 3 additions and 2 deletions

View File

@ -48,7 +48,7 @@ void BlackboardPlanEditor::_add_var() {
ERR_FAIL_NULL(plan);
int suffix = 1;
StringName var_name = default_var_name;
StringName var_name = default_var_name == StringName() ? "var" : default_var_name;
while (plan->has_var(var_name)) {
suffix += 1;
var_name = String(default_var_name) + itos(suffix);

View File

@ -106,7 +106,8 @@ void EditorPropertyVariableName::_status_pressed() {
ERR_FAIL_NULL(plan);
if (!plan->has_var(name_edit->get_text())) {
BlackboardPlanEditor::get_singleton()->set_defaults(name_edit->get_text(),
expected_type, default_hint, default_hint_string, default_value);
expected_type == Variant::NIL ? Variant::FLOAT : expected_type,
default_hint, default_hint_string, default_value);
}
BlackboardPlanEditor::get_singleton()->edit_plan(plan);
BlackboardPlanEditor::get_singleton()->popup_centered();