mirror of
https://github.com/godotengine/godot.git
synced 2025-01-24 21:01:50 +08:00
Auto-assign default value for variable in visual script on type changing
This commit is contained in:
parent
add3a825f0
commit
8d240f467d
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user