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 1 commit
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
14 changes: 14 additions & 0 deletions tutorials/scripting/gdscript/gdscript_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1951,6 +1951,20 @@ 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, hence they become available in other scripts without the need to `load` or `preload` them. For example::

# In a file 'game.gd'.

# If you uncomment the next line, you will trigger a warning:
# The variable "Character" has the same name as a global class defined in "character.gd".
# var Character = load("character.gd")

var player: Character

func new_game() -> void:
player = Character.new()


.. note::

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