Skip to content

Commit 6a02b17

Browse files
committed
Fix only instantiate default property once
1 parent e53bf54 commit 6a02b17

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/script-language/LuaScriptInstance.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ GDExtensionBool get_func(LuaScriptInstance *p_instance, const StringName *p_name
9797

9898
// d) fallback to default property value, if there is one
9999
if (property) {
100-
*p_value = property->instantiate_default_value();
100+
Variant value = property->instantiate_default_value();
101+
p_instance->data->rawset(*p_name, value);
102+
*p_value = value;
101103
return true;
102104
}
103105

test/gdscript_tests/test_class.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func test_signal() -> bool:
2727

2828
func test_array_properties() -> bool:
2929
var obj = test_class.new()
30+
var empty_array = obj.empty_array
3031
assert(obj.empty_array == [])
32+
assert(is_same(empty_array, obj.empty_array))
3133
assert(!is_same(obj.empty_array, test_class.get_property_default_value("empty_array")), "Properties should be duplicated on instantiation")
3234
assert(obj.preinitialized_array == [1, 2, 3])
3335
assert(!is_same(obj.preinitialized_array, test_class.get_property_default_value("preinitialized_array")), "Properties should be duplicated on instantiation")

0 commit comments

Comments
 (0)