diff --git a/tutorials/scripting/c_sharp/c_sharp_exports.rst b/tutorials/scripting/c_sharp/c_sharp_exports.rst index 1e34cdc8e27..13eba7b8962 100644 --- a/tutorials/scripting/c_sharp/c_sharp_exports.rst +++ b/tutorials/scripting/c_sharp/c_sharp_exports.rst @@ -293,7 +293,18 @@ Since Godot 4.0, nodes can be directly exported without having to use NodePaths. [Export] public Node Node { get; set; } -Custom node classes can also be used, see :ref:`doc_c_sharp_global_classes`. +A specific type of node can also be directly exported. The list of nodes shown +after pressing "Assign" in the inspector is filtered to the specified type, and +only a correct node can be assigned. + +.. code-block:: csharp + + [Export] + public Sprite2D Sprite2D { get; set; } + +Custom node classes can also be exported directly. The filtering behavior +depends on whether the custom class is a +:ref:`global class `. Exporting NodePaths like in Godot 3.x is still possible, in case you need it: diff --git a/tutorials/scripting/c_sharp/c_sharp_global_classes.rst b/tutorials/scripting/c_sharp/c_sharp_global_classes.rst index d595fd94784..9983dcab266 100644 --- a/tutorials/scripting/c_sharp/c_sharp_global_classes.rst +++ b/tutorials/scripting/c_sharp/c_sharp_global_classes.rst @@ -4,8 +4,13 @@ C# global classes ================= Global classes (also known as named scripts) are types registered in Godot's editor so they can be used -more conveniently. These classes show up in the *Add Node* and *Create Resource* dialogs, -and :ref:`exported properties ` are restricted to instances of the global class or derived classes. +more conveniently. + +- Global classes show up in the *Add Node* and *Create Resource* dialogs. +- If an :ref:`exported property ` is a global class, the + inspector restricts assignment, allowing only instances of that global class + or any derived classes. + Global classes are registered with the ``[GlobalClass]`` attribute. .. code-block:: csharp @@ -21,8 +26,33 @@ The ``MyNode`` type will be registered as a global class with the same name as t .. image:: img/globalclasses_addnode.webp -The ``[Icon]`` attribute also allows to provide the path to an icon so it can -be used as the class' icon in the editor. +The *Select a Node* window for the ``MyNode`` exported property filters the list +of nodes in the scene to match the assignment restriction. + +.. code-block:: csharp + + public partial class Main : Node + { + [Export] + public MyNode MyNode { get; set; } + } + +.. image:: img/globalclasses_exportednode.webp + +If a custom type isn't registered as a global class, the assignment is +restricted to the Godot type the custom type is based on. For example, inspector +assignments to an export of the type ``MySimpleSprite2D`` are restricted to +``Sprite2D`` and derived types. + +.. code-block:: csharp + + public partial class MySimpleSprite2D : Sprite2D + { + } + +When combined with the ``[GlobalClass]`` attribute, the ``[Icon]`` attribute +allows providing a path to an icon to show when the class is displayed in the +editor. .. code-block:: csharp diff --git a/tutorials/scripting/c_sharp/img/globalclasses_addnode.webp b/tutorials/scripting/c_sharp/img/globalclasses_addnode.webp index 8e8378dc271..8abd93f395d 100644 Binary files a/tutorials/scripting/c_sharp/img/globalclasses_addnode.webp and b/tutorials/scripting/c_sharp/img/globalclasses_addnode.webp differ diff --git a/tutorials/scripting/c_sharp/img/globalclasses_createresource.webp b/tutorials/scripting/c_sharp/img/globalclasses_createresource.webp index 80de8c1111d..d11767916d5 100644 Binary files a/tutorials/scripting/c_sharp/img/globalclasses_createresource.webp and b/tutorials/scripting/c_sharp/img/globalclasses_createresource.webp differ diff --git a/tutorials/scripting/c_sharp/img/globalclasses_exportednode.webp b/tutorials/scripting/c_sharp/img/globalclasses_exportednode.webp new file mode 100644 index 00000000000..0fa733fec11 Binary files /dev/null and b/tutorials/scripting/c_sharp/img/globalclasses_exportednode.webp differ diff --git a/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty1.webp b/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty1.webp index a9cca77ae03..c12b05e3ec7 100644 Binary files a/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty1.webp and b/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty1.webp differ diff --git a/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty2.webp b/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty2.webp index 7fcab655197..862d967fe76 100644 Binary files a/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty2.webp and b/tutorials/scripting/c_sharp/img/globalclasses_exportedproperty2.webp differ