Up to date

This page is up to date for Godot 4.0. If you still find outdated information, please open an issue.

GDScript documentation comments

In GDScript, comments can be used to document your code and add descriptions to the members of a script. There are two differences between a normal comment and a documentation comment. Firstly, a documentation comment should start with double hash symbols ##. Secondly, it must immediately precede a script member, or for script descriptions, be placed at the top of the script. If an exported variable is documented, its description is used as a tooltip in the editor. This documentation can be generated as XML files by the editor.

Documenting a script

Comments documenting a script must come before any member documentation. A suggested format for script documentation can be divided into three parts.

  • A brief description of the script.

  • Detailed description.

  • Tutorials.

To separate these from each other, the documentation comments use special tags. The tag must be at the beginning of a line (ignoring preceding white space) and must have the format @, followed by the keyword, and finishing with a colon.

Tags

Brief description

No tag and lives at the very beginning of the documentation section.

Description

Use one blank line to separate the description from the brief.

Tutorial

@tutorial:
@tutorial(The Title Here):

For example:

  1. extends Node2D
  2. ## A brief description of the class's role and functionality.
  3. ##
  4. ## The description of the script, what it can do,
  5. ## and any further detail.
  6. ##
  7. ## @tutorial: https://the/tutorial1/url.com
  8. ## @tutorial(Tutorial2): https://the/tutorial2/url.com

Warning

If there is any space in between the tag name and colon, for example @tutorial :, it won’t be treated as a valid tag and will be ignored.

Note

When the description spans multiple lines, the preceding and trailing white spaces will be stripped and joined with a single space. To preserve the line break use [br]. See also BBCode and class reference below.

Documenting script members

Documentation of a script member must immediately precede the member or its annotations if it has any. The exception to this is enum values whose description should be on the same line as the enum for readability. The description can have more than one line but every line must start with the double hash symbol ## to be considered as part of the documentation. The script documentation will update in the editor help window every time the script is updated. If any member variable or function name starts with an underscore, it will be treated as private. It will not appear in the documentation and will be ignored in the help window.

Members that are applicable for documentation:

  • Inner class

  • Constant

  • Function

  • Signal

  • Variable

  • Enum

  • Enum value

Example

  1. extends Node2D
  2. ## A brief description of the class's role and functionality.
  3. ##
  4. ## The description of the script, what it can do,
  5. ## and any further detail.
  6. ##
  7. ## @tutorial: https://the/tutorial1/url.com
  8. ## @tutorial(Tutorial2): https://the/tutorial2/url.com
  9. ## The description of a constant.
  10. const GRAVITY = 9.8
  11. ## The description of a signal.
  12. signal my_signal
  13. ## This is a description of the below enums. Note below that
  14. ## the enum values are documented on the same line as the enum.
  15. enum Direction {
  16. UP = 0, ## Direction up.
  17. DOWN = 1, ## Direction down.
  18. LEFT = 2, ## Direction left.
  19. RIGHT = 3, ## Direction right.
  20. }
  21. ## The description of a constant.
  22. const GRAVITY = 9.8
  23. ## The description of the variable v1.
  24. var v1
  25. ## This is a multiline description of the variable v2.[br]
  26. ## The type information below will be extracted for the documentation.
  27. var v2: int
  28. ## If the member has any annotation, the annotation should
  29. ## immediately precede it.
  30. @export
  31. var v3 := some_func()
  32. ## As the following function is documented, even though its name starts with
  33. ## an underscore, it will appear in the help window.
  34. func _fn(p1: int, p2: String) -> int:
  35. return 0
  36. # The below function isn't documented and its name starts with an underscore
  37. # so it will treated as private and will not be shown in the help window.
  38. func _internal() -> void:
  39. pass
  40. ## Documenting an inner class.
  41. ##
  42. ## The same rules apply here. The documentation must
  43. ## immediately precede the class definition.
  44. ##
  45. ## @tutorial: https://the/tutorial/url.com
  46. class Inner:
  47. ## Inner class variable v4.
  48. var v4
  49. ## Inner class function fn.
  50. func fn(): pass

BBCode and class reference

The editor help window which renders the documentation supports bbcode. As a result it’s possible to align and format the documentation. Color texts, images, fonts, tables, URLs, animation effects, etc. can be added with the bbcode.

Godot’s class reference supports BBCode-like tags. They add nice formatting to the text which could also be used in the documentation. See also class reference bbcode.

Whenever you link to a member of another class, you need to specify the class name. For links to the same class, the class name is optional and can be omitted.

Here’s the list of available tags:

Tag and Description

Example

Result

[Class]
Link to class

Move the [Sprite2D].

Move the Sprite2D.

[annotation Class.name]
Link to annotation

See [annotation @GDScript.@export].

See @GDScript.@export.

[constant Class.name]
Link to constant

See [constant @GlobalScope.KEY_F1].

See @GlobalScope.KEY_F1.

[enum Class.name]
Link to enum

See [enum Mesh.ArrayType].

See Mesh.ArrayType.

[method Class.name]
Link to method

Call [method Node3D.hide].

Call Node3D.hide().

[member Class.name]
Link to member

Get [member Node2D.scale].

Get Node2D.scale.

[signal Class.name]
Link to signal

Emit [signal Node.renamed].

Emit Node.renamed.

[theme_item Class.name]
Link to theme item

See [theme_item Label.font].

See Label.font.

[param name]
Formats a parameter name (as code)

Takes [param size] for the size.

Takes size for the size.

[br]
Line break
Line 1.[br]
Line 2.
Line 1.
Line 2.
[b] [/b]
Bold

Some [b]bold[/b] text.

Some bold text.

[i] [/i]
Italic

Some [i]italic[/i] text.

Some italic text.

[kbd] [/kbd]
Keyboard/mouse shortcut

Some [kbd]Ctrl + C[/kbd] key.

Some Ctrl + C key.

[code] [/code]
Monospace

Some [code]monospace[/code] text.

Some monospace text.

[codeblock] [/codeblock]
Multiline preformatted block

See below.

See below.

Note

  1. Currently only @GDScript has annotations.

  2. [code] disables BBCode until the parser encounters [/code].

  3. [codeblock] disables BBCode until the parser encounters [/codeblock].

Warning

Use [codeblock] for pre-formatted code blocks. Inside [codeblock], always use four spaces for indentation (the parser will delete tabs).

  1. ## Do something for this plugin. Before using the method
  2. ## you first have to [method initialize] [MyPlugin].[br]
  3. ## [color=yellow]Warning:[/color] Always [method clean] after use.[br]
  4. ## Usage:
  5. ## [codeblock]
  6. ## func _ready():
  7. ## the_plugin.initialize()
  8. ## the_plugin.do_something()
  9. ## the_plugin.clean()
  10. ## [/codeblock]
  11. func do_something():
  12. pass