@@ -4,8 +4,13 @@ C# global classes
44=================
55
66Global classes (also known as named scripts) are types registered in Godot's editor so they can be used
7- more conveniently. These classes show up in the *Add Node * and *Create Resource * dialogs,
8- and :ref: `exported properties <doc_c_sharp_exports >` are restricted to instances of the global class or derived classes.
7+ more conveniently.
8+
9+ - Global classes show up in the *Add Node * and *Create Resource * dialogs.
10+ - If an :ref: `exported property <doc_c_sharp_exports >` is a global class, the
11+ inspector restricts assignment, allowing only instances of that global class
12+ or any derived classes.
13+
914Global classes are registered with the ``[GlobalClass] `` attribute.
1015
1116.. code-block :: csharp
@@ -21,8 +26,33 @@ The ``MyNode`` type will be registered as a global class with the same name as t
2126
2227.. image :: img/globalclasses_addnode.webp
2328
24- The ``[Icon] `` attribute also allows to provide the path to an icon so it can
25- be used as the class' icon in the editor.
29+ The *Select a Node * window for the ``MyNode `` exported property filters the list
30+ of nodes in the scene to match the assignment restriction.
31+
32+ .. code-block :: csharp
33+
34+ public partial class Main : Node
35+ {
36+ [Export ]
37+ public MyNode MyNode { get ; set ; }
38+ }
39+
40+ .. image :: img/globalclasses_exportednode.webp
41+
42+ If a custom type isn't registered as a global class, the assignment is
43+ restricted to the Godot type the custom type is based on. For example, inspector
44+ assignments to an export of the type ``MySimpleSprite2D `` are restricted to
45+ ``Sprite2D `` and derived types.
46+
47+ .. code-block :: csharp
48+
49+ public partial class MySimpleSprite2D : Sprite2D
50+ {
51+ }
52+
53+ When combined with the ``[GlobalClass] `` attribute, the ``[Icon] `` attribute
54+ allows providing a path to an icon to show when the class is displayed in the
55+ editor.
2656
2757.. code-block :: csharp
2858
0 commit comments