Skip to content

Commit

Permalink
Merge pull request godotengine#44918 from Chaosus/vs_assign_default_v…
Browse files Browse the repository at this point in the history
…alue

Auto-assign default value for variable in visual script on type changing
  • Loading branch information
akien-mga authored Jan 7, 2021
2 parents c7b4514 + 8d240f4 commit efdca23
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 efdca23

Please sign in to comment.