GD0003.rst 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. GD0003: Found multiple classes with the same name in the same script file
  2. =========================================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0003
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Non-breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. A script file contains multiple types that derives from ``GodotObject`` with
  14. a name that matches the script file. Only one type in the script file should
  15. match the file name.
  16. Rule description
  17. ----------------
  18. Godot requires scripts to have a unique path so every type must be defined on its
  19. own file and the type name must match the file name.
  20. .. code-block:: csharp
  21. public partial class MyNode : Node { }
  22. namespace DifferentNamespace
  23. {
  24. // Invalid because there's already a type with the name MyNode in this file.
  25. public partial class MyNode : Node { }
  26. }
  27. // Invalid because there's already a type with the name MyNode in this file.
  28. public partial class MyNode<T> : Node { }
  29. How to fix violations
  30. ---------------------
  31. To fix a violation of this rule, move each type declaration to a different file.
  32. When to suppress warnings
  33. -------------------------
  34. Do not suppress a warning from this rule. Types that derive from ``GodotObject``
  35. must have a unique path otherwise the engine can't load the script by path,
  36. resulting in unexpected runtime errors.