-
-
Notifications
You must be signed in to change notification settings - Fork 691
Closed
Labels
bugThis has been identified as a bugThis has been identified as a bug
Milestone
Description
Godot version
v4.1.beta2.mono.official [a2575cba4]
godot-cpp version
System information
Windows 11 22H2
Issue description
If my method takes an Array parameter, it behaves as a reference to the original array which was passed in from GDScript, so it can be modified.
But if I change that to a TypedArray, the array is instead copied, and any changes are therefore lost.
void MyObject::AppendToArray(Array a)
{
// works as expected
a.append(100);
}
void MyObject::AppendToTypedArray(TypedArray<int> b)
{
// original array is unchanged
b.append(200);
}var a = []
var b: Array[int] = []
MyObject.AppendToArray(a)
MyObject.AppendToTypedArray(b)
print(a) # [100]
print(b) # []This is because the TypedArray constructors call a builtin Array constructor which makes a copy.
godot-cpp/include/godot_cpp/variant/typed_array.hpp
Lines 67 to 72 in 82edc89
| _FORCE_INLINE_ TypedArray(const Variant &p_variant) : \ | |
| Array(p_variant.operator Array(), m_variant_type, StringName(), Variant()) { \ | |
| } \ | |
| _FORCE_INLINE_ TypedArray(const Array &p_array) : \ | |
| Array(p_array, m_variant_type, StringName(), Variant()) { \ | |
| } \ |
If I change those base constructor calls to the single-argument Array constructor, it fixes the issue for me, but I'm not sure what the proper fix should be.
Steps to reproduce
Bind a method which takes a TypedArray parameter and modifies the array.
Minimal reproduction project
N/A
apples
Metadata
Metadata
Assignees
Labels
bugThis has been identified as a bugThis has been identified as a bug