summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2021-01-04 21:10:04 +0300
committerYuri Roubinsky <chaosus89@gmail.com>2021-01-04 21:10:04 +0300
commit8d240f467d92534ca84b89f0167ac58ea04d316c (patch)
tree7fb69d4c9443c14aac4265d7189425f2e5329d75
parentadd3a825f0cb0c82026694b084f883f6f70be641 (diff)
Auto-assign default value for variable in visual script on type changing
-rw-r--r--modules/visual_script/visual_script_editor.cpp13
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();