Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify the global registration of named_classes #10679

Merged
merged 3 commits into from
Feb 15, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tutorials/scripting/gdscript/gdscript_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,25 @@ If you want to use ``extends`` too, you can keep both on the same line::

class_name MyNode extends Node

Named classes are globally registered, which means they become available to use
in other scripts without the need to ``load`` or ``preload`` them:

.. code-block:: gdscript

var player

func _ready():
player = Character.new()

Using the name of a named class as a variable name will cause a
:ref:`SHADOWED_GLOBAL_IDENTIFIER <class_ProjectSettings_property_debug/gdscript/warnings/shadowed_global_identifier>`
warning. For example, using ``Character`` as a variable name will shadow the
``Character`` class you just defined, and cause a warning:

.. code-block:: gdscript

var Character

.. note::

Godot initializes non-static variables every time you create an instance,
Expand Down
Loading