You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
voidMyObject::AppendToArray(Array a)
{
// works as expected
a.append(100);
}
voidMyObject::AppendToTypedArray(TypedArray<int> b)
{
// original array is unchanged
b.append(200);
}
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
The text was updated successfully, but these errors were encountered:
Godot version
v4.1.beta2.mono.official [a2575cba4]
godot-cpp version
82edc89
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.This is because the
TypedArray
constructors call a builtinArray
constructor which makes a copy.godot-cpp/include/godot_cpp/variant/typed_array.hpp
Lines 67 to 72 in 82edc89
https://github.com/godotengine/godot/blob/7b170d12cf0f8b3a15572fd203aa5cba840975f3/core/variant/array.cpp#L756-L761
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
The text was updated successfully, but these errors were encountered: