Skip to content

Commit

Permalink
Auto-assign default value for variable in visual script on type changing
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaosus committed Jan 4, 2021
1 parent add3a82 commit 8d240f4
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions modules/visual_script/visual_script_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,19 @@ class VisualScriptEditorVariableEdit : public Object {
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();
Expand Down

0 comments on commit 8d240f4

Please sign in to comment.