From 8f2ea4f2ffd5fdee5b3955ad00c621b14ef8862d Mon Sep 17 00:00:00 2001 From: Sai Nane Date: Thu, 28 Nov 2024 14:15:51 +0000 Subject: [PATCH] Fix documentation on exportable C# native arrays It's quite hard to tell what is and isn't permissible from the current description, and there are both false positives and negatives. This makes explicit what is and isn't permissible, and suggests a general workaround when the relevant diagnostic is raised for a native array type. --- tutorials/scripting/c_sharp/c_sharp_exports.rst | 12 +++++++++++- tutorials/scripting/c_sharp/diagnostics/GD0102.rst | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tutorials/scripting/c_sharp/c_sharp_exports.rst b/tutorials/scripting/c_sharp/c_sharp_exports.rst index d6880f09b69..cbc15811737 100644 --- a/tutorials/scripting/c_sharp/c_sharp_exports.rst +++ b/tutorials/scripting/c_sharp/c_sharp_exports.rst @@ -573,7 +573,14 @@ The default value of Godot dictionaries is null. A different default can be spec Exporting C# arrays ^^^^^^^^^^^^^^^^^^^ -C# arrays can exported as long as the element type is a :ref:`Variant-compatible type `. +.. + See Godot.SourceGenerators.MarshalUtils.ConvertManagedTypeToMarshalType for the function which determines what can be marshalled + +C# arrays can exported as long as it not multi-dimensional, and the element type is one of the following: + +* A native C# ``byte``, ``int``/``Int32``, ``Int64``, ``float``, ``double``, or ``string``. +* Anything derived from ``GodotObject``. +* Godot's ``Vector2``, ``Vector3``, ``Vector4``, ``Color``, ``StringName``, ``NodePath``, or ``Rid``. .. code-block:: csharp @@ -583,6 +590,9 @@ C# arrays can exported as long as the element type is a :ref:`Variant-compatible [Export] public NodePath[] NodePaths { get; set; } +Other element types, even other :ref:`Variant-compatible types ` such as ``Plane`` or ``Transform2D``, will not work. +If you get a :ref:`GD0102 ` error, use a ``Godot.Collections.Array`` instead. + The default value of C# arrays is null. A different default can be specified: .. code-block:: csharp diff --git a/tutorials/scripting/c_sharp/diagnostics/GD0102.rst b/tutorials/scripting/c_sharp/diagnostics/GD0102.rst index 3f76f8bb81d..6b2eb22ce79 100644 --- a/tutorials/scripting/c_sharp/diagnostics/GD0102.rst +++ b/tutorials/scripting/c_sharp/diagnostics/GD0102.rst @@ -1,3 +1,5 @@ +.. _doc_c_sharp_diagnostics_gd0102: + GD0102: The type of the exported member is not supported ========================================================