diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-01-07 16:51:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-07 16:51:01 +0100 |
commit | efdca23f8798b03330e25d2d615c57adaab237af (patch) | |
tree | 9a9accd5c3f9297bf7b36e65aaf15c0cf7a46315 | |
parent | c7b45141de9538e06dee0f4fd7799ff75d5f4eff (diff) | |
parent | 8d240f467d92534ca84b89f0167ac58ea04d316c (diff) |
Merge pull request #44918 from Chaosus/vs_assign_default_value
Auto-assign default value for variable in visual script on type changing
-rw-r--r-- | modules/visual_script/visual_script_editor.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index 3fbf19a48d..1e82259e59 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -227,6 +227,19 @@ protected: undo_redo->create_action(TTR("Set Variable Type")); undo_redo->add_do_method(script.ptr(), "set_variable_info", var, dc); undo_redo->add_undo_method(script.ptr(), "set_variable_info", var, d); + + // Setting the default value. + Variant::Type type = (Variant::Type)(int)p_value; + if (type != Variant::NIL) { + Variant default_value; + Callable::CallError ce; + Variant::construct(type, default_value, nullptr, 0, ce); + if (ce.error == Callable::CallError::CALL_OK) { + undo_redo->add_do_method(script.ptr(), "set_variable_default_value", var, default_value); + undo_redo->add_undo_method(script.ptr(), "set_variable_default_value", var, dc["value"]); + } + } + undo_redo->add_do_method(this, "_var_changed"); undo_redo->add_undo_method(this, "_var_changed"); undo_redo->commit_action(); |