Skip to content

Commit

Permalink
Fix documentation on exportable C# native arrays
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
esainane committed Nov 28, 2024
1 parent 1a72210 commit 6324f68
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tutorials/scripting/c_sharp/c_sharp_exports.rst
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,13 @@ 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 <c_sharp_variant_compatible_types>`.
C# arrays can exported as long as it not multi-dimensional, and the element type is one of the following:

..
See Godot.SourceGenerators.MarshalUtils.ConvertManagedTypeToMarshalType for the function which determines what can be marshalled
* 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
Expand All @@ -583,6 +589,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 <c_sharp_variant_compatible_types>` such as ``Plane`` or ``Transform2D``, will not work.
If you get a :ref:`GD0102 <doc_c_sharp_diagnostics_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
Expand Down
2 changes: 2 additions & 0 deletions tutorials/scripting/c_sharp/diagnostics/GD0102.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _doc_c_sharp_diagnostics_gd0102:

GD0102: The type of the exported member is not supported
========================================================

Expand Down

0 comments on commit 6324f68

Please sign in to comment.