Cannot export C# array of type Vector2I, Vector3I, Vector4I: "GD0102: The type of the exported field is not supported"
Tested versions
4.2.2 stable
System information
Windows 10, Godot 4.2.2 stable
Issue description
In the manual, it says:
C# arrays can exported as long as the element type is a Variant-compatible type.
Vector2I, Vector3I, and Vector4I are listed as Variant compatible types in the manual.
However, when trying to export e.g. an Vector2I array, Godot gives the error: "GD0102: The type of the exported field is not supported"
Steps to reproduce
Create a C# script with the line:
[Export] private Vector2I[] testI;
then try to compile.
Minimal reproduction project (MRP)
N/A
Try exporting as a typed array, see here, i.e. Godot.Collections.Array<Vector2I>, this is probably because the array itself isn't supported, unlike Vector3[], because there's no PackedVector2iArray
That works, but I'll maintain that according to the manual exporting the C# array should also work, so I'll leave the issue open.
Confirmed on my end (master
88f3b5f)
This is somewhat vaguely hinted at in the documentation for C# Variant where it notes that a standard array is equivalent to Godot.Collections.Array and notes the packed array equivalents right below (e.g. byte[] or Vector3[])
In the manual, it says:
C# arrays can exported as long as the element type is a Variant-compatible type.
This is incorrect, and likely a remnant of Godot 3. It should be updated to say C# arrays are only supported if there's a PackedArray equivalent.
This is somewhat vaguely hinted at in the documentation for C# Variant where it notes that a standard array is equivalent to
Godot.Collections.Arrayand notes the packed array equivalents right below (e.g.byte[]orVector3[])
I think you are misreading the table. The first column represents the elements of the Variant.Type enum (i.e.: the native Godot types), and the second column represents the C# types that they are equivalent to. So the table is saying that the Godot array type is represented as Godot.Collections.Array in C#. It doesn't say anything about C# arrays other than the ones listed explicitly as equivalent of the corresponding PackedArray types.
I found that exporting native C# arrays of a godot object type (e.g. resource) does work as well, so it's not just packed arrays that work.
That's true, and a few others like Rid[], NodePath[] and StringName[]. But I don't think we should encourage using those, since it requires copying every element of the array into a Godot.Collections.Array anyway for marshalling. It's easier to think of C# arrays as the equivalent of PackedArrays, than to remember which element types are supported.
I think https://github.com/godotengine/godot-docs/pull/10332 will fix this issue in the docs?