Skip to content

Improve documentation on constructors in GDScript basics - #12138

Open
Calinou wants to merge 1 commit into
godotengine:masterfrom
Calinou:gdscript-basics-constructor
Open

Improve documentation on constructors in GDScript basics#12138
Calinou wants to merge 1 commit into
godotengine:masterfrom
Calinou:gdscript-basics-constructor

Conversation

@Calinou

@Calinou Calinou commented Jul 9, 2026

Copy link
Copy Markdown
Member

@Calinou
Calinou requested review from a team as code owners July 9, 2026 17:50


# Inner class
# Inner class (also called "subclass").

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a thing that we are calling them subclasses in official stuff?


.. warning::

When instancing nodes through ``class_name`` or other mechanisms, the

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by instancing through class_name.

You can totally inherit Node and provide a constructor with required arguments, as long as you create it manually at runtime. This is only an issue when trying to put the node into a scene. (And I think it's an issue for custom resources in general, because they don't load correctly iirc.)

# This is called when the class is instantiated with `new()`.
# A constructor method may have parameters, optionally with default values
# and static type hints.
func _init():

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment you linked asked for an example on how to call init with args. Maybe we could pass the message into _init as paramter to make clear how it works.

Note that every class has an implicit constructor that is always called
The class constructor, called on class instantiation with ``new()``, is named
``_init()``. Like methods, the class constructor may have one or more
parameters, which can have default values. These parameters can be passed when

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if worth mentioning, but varargs seem to be supported in constructors as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants