@@ -30,6 +30,7 @@ Here is a complete class example based on these guidelines:
3030
3131 class_name StateMachine
3232 extends Node
33+ uses Activatable
3334 ## Hierarchical State machine for the player.
3435 ##
3536 ## Initializes states and delegates engine callbacks ([method Node._physics_process],
@@ -629,6 +630,8 @@ code. As a summary table:
629630+---------------+----------------+----------------------------------------------------+
630631| Class names | PascalCase | ``class_name YAMLParser `` |
631632+---------------+----------------+----------------------------------------------------+
633+ | Trait names | PascalCase | ``trait_name Interactable `` |
634+ +---------------+----------------+----------------------------------------------------+
632635| Node names | PascalCase | ``Camera3D ``, ``Player `` |
633636+---------------+----------------+----------------------------------------------------+
634637| Functions | snake_case | ``func load_level(): `` |
@@ -647,7 +650,7 @@ code. As a summary table:
647650File names
648651~~~~~~~~~~
649652
650- Use snake_case for file names. For named classes, convert the PascalCase class
653+ Use snake_case for file names. For named classes and traits , convert the PascalCase class or trait
651654name to snake_case::
652655
653656 # This file should be saved as `weapon.gd`.
@@ -660,20 +663,26 @@ name to snake_case::
660663 class_name YAMLParser
661664 extends Object
662665
666+ ::
667+
668+ # This file should be saved as `interactable.gdt`.
669+ trait_name Interactable
670+ extends Node
671+
663672This is consistent with how C++ files are named in Godot's source code. This
664673also avoids case sensitivity issues that can crop up when exporting a project
665674from Windows to other platforms.
666675
667676Classes and nodes
668677~~~~~~~~~~~~~~~~~
669678
670- Use PascalCase for class and node names:
679+ Use PascalCase for class, trait, and node names:
671680
672681::
673682
674683 extends CharacterBody3D
675684
676- Also use PascalCase when loading a class into a constant or a variable:
685+ Also use PascalCase when loading a class or trait into a constant or a variable:
677686
678687::
679688
@@ -766,23 +775,24 @@ We suggest to organize GDScript code this way:
766775 01. @tool
767776 02. class_name
768777 03. extends
769- 04. ## docstring
770-
771- 05. signals
772- 06. enums
773- 07. constants
774- 08. @export variables
775- 09. public variables
776- 10. private variables
777- 11. @onready variables
778-
779- 12. optional built-in virtual _init method
780- 13. optional built-in virtual _enter_tree() method
781- 14. built-in virtual _ready method
782- 15. remaining built-in virtual methods
783- 16. public methods
784- 17. private methods
785- 18. subclasses
778+ 04. uses
779+ 05. ## docstring
780+
781+ 06. signals
782+ 07. enums
783+ 08. constants
784+ 09. @export variables
785+ 10. public variables
786+ 11. private variables
787+ 12. @onready variables
788+
789+ 13. optional built-in virtual _init method
790+ 14. optional built-in virtual _enter_tree() method
791+ 15. built-in virtual _ready method
792+ 16. remaining built-in virtual methods
793+ 17. public methods
794+ 18. private methods
795+ 19. subclasses
786796
787797We optimized the order to make it easy to read the code from top to bottom, to
788798help developers reading the code for the first time understand how it works, and
@@ -808,6 +818,8 @@ global type in your project using this feature. For more information, see
808818:ref: `doc_gdscript `.
809819
810820Then, add the ``extends `` keyword if the class extends a built-in type.
821+ If the class uses any traits, add the ``uses `` keyword along with all of the trait
822+ names (or filepaths, if the traits are unnamed) of the traits it uses.
811823
812824Following that, you should have the class's optional
813825:ref: `documentation comments <doc_gdscript_documentation_comments >`.
@@ -818,6 +830,7 @@ and how other developers should use it, for example.
818830
819831 class_name MyNode
820832 extends Node
833+ uses MyTrait
821834 ## A brief description of the class's role and functionality.
822835 ##
823836 ## The description of the script, what it can do,
0 commit comments