GD0401.rst 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. GD0401: The class must derive from Godot.GodotObject or a derived class
  2. =======================================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0401
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Breaking - If changing the inheritance chain
  9. Non-breaking - If removing the ``[GlobalClass]`` attribute
  10. **Enabled by default** Yes
  11. ==================================== ======================================
  12. Cause
  13. -----
  14. A type annotated with the ``[GlobalClass]`` attribute does not derive from
  15. ``GodotObject``.
  16. Rule description
  17. ----------------
  18. The ``[GlobalClass]`` has no effect for types that don't derive from ``GodotObject``.
  19. Every :ref:`global class <doc_c_sharp_global_classes>` must ultimately derive from
  20. ``GodotObject`` so it can be marshalled.
  21. .. code-block:: csharp
  22. // This type is not registered as a global class because it doesn't derive from GodotObject.
  23. [GlobalClass]
  24. class SomeType { }
  25. // This type is a global class because it derives from Godot.Node
  26. // which ultimately derives from GodotObject.
  27. [GlobalClass]
  28. class MyNode : Node { }
  29. // This type is a global class because it derives from Godot.Resource
  30. // which ultimately derives from GodotObject.
  31. [GlobalClass]
  32. class MyResource : Resource { }
  33. How to fix violations
  34. ---------------------
  35. To fix a violation of this rule, change the type to derive from ``GodotObject``
  36. or remove the ``[GlobalClass]`` attribute.
  37. When to suppress warnings
  38. -------------------------
  39. Do not suppress a warning from this rule. Adding the ``[GlobalClass]`` to a type
  40. that doesn't derive from ``GodotObject`` is an easy mistake to make and this
  41. warning helps users realize that it may result in unexpected errors.