@@ -30,6 +30,7 @@ Here is a complete class example based on these guidelines:
30
30
31
31
class_name StateMachine
32
32
extends Node
33
+ uses Activatable
33
34
## Hierarchical State machine for the player.
34
35
##
35
36
## Initializes states and delegates engine callbacks ([method Node._physics_process],
@@ -629,6 +630,8 @@ code. As a summary table:
629
630
+---------------+----------------+----------------------------------------------------+
630
631
| Class names | PascalCase | ``class_name YAMLParser `` |
631
632
+---------------+----------------+----------------------------------------------------+
633
+ | Trait names | PascalCase | ``trait_name Interactable `` |
634
+ +---------------+----------------+----------------------------------------------------+
632
635
| Node names | PascalCase | ``Camera3D ``, ``Player `` |
633
636
+---------------+----------------+----------------------------------------------------+
634
637
| Functions | snake_case | ``func load_level(): `` |
@@ -647,7 +650,7 @@ code. As a summary table:
647
650
File names
648
651
~~~~~~~~~~
649
652
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
651
654
name to snake_case::
652
655
653
656
# This file should be saved as `weapon.gd`.
@@ -660,20 +663,26 @@ name to snake_case::
660
663
class_name YAMLParser
661
664
extends Object
662
665
666
+ ::
667
+
668
+ # This file should be saved as `interactable.gdt`.
669
+ trait_name Interactable
670
+ extends Node
671
+
663
672
This is consistent with how C++ files are named in Godot's source code. This
664
673
also avoids case sensitivity issues that can crop up when exporting a project
665
674
from Windows to other platforms.
666
675
667
676
Classes and nodes
668
677
~~~~~~~~~~~~~~~~~
669
678
670
- Use PascalCase for class and node names:
679
+ Use PascalCase for class, trait, and node names:
671
680
672
681
::
673
682
674
683
extends CharacterBody3D
675
684
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:
677
686
678
687
::
679
688
@@ -766,23 +775,24 @@ We suggest to organize GDScript code this way:
766
775
01. @tool
767
776
02. class_name
768
777
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
786
796
787
797
We optimized the order to make it easy to read the code from top to bottom, to
788
798
help 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
808
818
:ref: `doc_gdscript `.
809
819
810
820
Then, 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.
811
823
812
824
Following that, you should have the class's optional
813
825
:ref: `documentation comments <doc_gdscript_documentation_comments >`.
@@ -818,6 +830,7 @@ and how other developers should use it, for example.
818
830
819
831
class_name MyNode
820
832
extends Node
833
+ uses MyTrait
821
834
## A brief description of the class's role and functionality.
822
835
##
823
836
## The description of the script, what it can do,
0 commit comments