From 602fc00e56f42bbe55f1556a54af0d4bcf93af0e Mon Sep 17 00:00:00 2001 From: Yuri Roubinsky Date: Mon, 11 Jan 2021 10:29:12 +0300 Subject: [PATCH] [3.2] Auto-assign default value for variable in visual script on type changing --- modules/visual_script/visual_script_editor.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index d2d22d3d953..6e115a5d4dd 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -251,6 +251,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; + Variant::CallError ce; + default_value = Variant::construct(type, NULL, 0, ce); + if (ce.error == Variant::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();