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 and deprecated/experimental marks.

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.

Tags

Brief description

No tag. Lives at the very beginning of the documentation section.

Description

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

Tutorial

@tutorial(The Title Here): https://example.com

Deprecated

@deprecated
@deprecated: Use [AnotherClass] instead.

Experimental

@experimental
@experimental: This class is unstable.

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://example.com/tutorial_1
  8. ## @tutorial(Tutorial 2): https://example.com/tutorial_2
  9. ## @experimental

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

Members that are applicable for documentation:

  • Signal

  • Enum

  • Enum value

  • Constant

  • Variable

  • Function

  • Inner class

Documentation of a script member must immediately precede the member or its annotations if it has any. 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.

Tags

Description

No tag.

Deprecated

@deprecated
@deprecated: Use [member another] instead.

Experimental

@experimental
@experimental: This method is incomplete.

For example:

  1. ## The description of the variable.
  2. ## @deprecated: Use [member other_var] instead.
  3. var my_var

Alternatively, you can use inline documentation comments:

  1. signal my_signal ## My signal.
  2. enum MyEnum { ## My enum.
  3. VALUE_A = 0, ## Value A.
  4. VALUE_B = 1, ## Value B.
  5. }
  6. const MY_CONST = 1 ## My constant.
  7. var my_var ## My variable.
  8. func my_func(): ## My func.
  9. pass
  10. class MyClass: ## My class.
  11. pass

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.

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

@deprecated and @experimental tags

You can mark a class or any of its members as deprecated or experimental. This will add the corresponding indicator in the built-in documentation viewer. Optionally, you can provide a short message explaining why the API is not recommended. This can be especially useful for plugin and library creators.

../../../_images/deprecated_and_experimental_tags.webp

  • Deprecated marks a non-recommended API that is subject to removal or incompatible change in a future major release. Usually the API is kept for backwards compatibility.

  • Experimental marks a new unstable API that may be changed or removed in the current major branch. Using this API is not recommended in production code.

Note

While technically you can use both @deprecated and @experimental tags on the same class/member, this is not recommended as it is against common conventions.

BBCode and class reference

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. Note that this is slightly different from the RichTextLabel 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.@rpc].

See @GDScript.@rpc.

[constant Class.name]
Link to constant

See [constant Color.RED].

See Color.RED.

[enum Class.name]
Link to enum

See [enum Mesh.ArrayType].

See Mesh.ArrayType.

[member Class.name]
Link to member (property)

Get [member Node2D.scale].

Get Node2D.scale.

[method Class.name]
Link to method

Call [method Node3D.hide].

Call Node3D.hide().

[constructor Class.name]
Link to built-in constructor

Use [constructor Color.Color].

Use Color.Color.

[operator Class.name]
Link to built-in operator

Use [operator Color.operator ].

Use Color.operator .

[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]
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.
[lb] [rb]
[ and ] respectively

[lb]b[rb]text[lb]/b[rb]

[b]text[/b]

[b] [/b]
Bold

Do [b]not[/b] call this method.

Do not call this method.

[i] [/i]
Italic

Returns the [i]global[/i] position.

Returns the global position.

[u] [/u]
Underline

[u]Always[/u] use this method.

Always use this method.
[s] [/s]
Strikethrough

[s]Outdated information.[/s]

Outdated information.
[color] [/color]
Color

[color=red]Error![/color]

Error!
[font] [/font]
Font

[font=res://mono.ttf]LICENSE[/font]

LICENSE
[img] [/img]
Image

[img width=32]res://icon.svg[/img]

../../../_images/icon.svg
[url] [/url]
Hyperlink
[center] [/center]
Horizontal centering

[center]2 + 2 = 4[/center]

2 + 2 = 4
[kbd] [/kbd]
Keyboard/mouse shortcut

Press [kbd]Ctrl + C[/kbd].

Press Ctrl + C.

[code] [/code]
Inline code fragment

Returns [code]true[/code].

Returns true.

[codeblock]
[/codeblock]
Multiline code block

See below.

See below.

Note

  1. Currently only @GDScript has annotations.

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

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

  4. [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

By default, [codeblock] highlights GDScript syntax. You can change it using the lang attribute. Currently supported options are:

  • [codeblock lang=text] disables syntax highlighting;

  • [codeblock lang=gdscript] highlights GDScript syntax;

  • [codeblock lang=csharp] highlights C# syntax (only in .NET version).


User-contributed notes

Please read the User-contributed notes policy before submitting a comment.

Previous Next