GD0108.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. GD0108: The exported tool button is not in a tool class
  2. =======================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0108
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Non-breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. A property is annotated with the ``[ExportToolButton]`` attribute in a class that
  14. is **not** annotated with the ``[Tool]`` attribute.
  15. Rule description
  16. ----------------
  17. The ``[ExportToolButton]`` is used to create clickable buttons in the inspector so,
  18. like every other script that runs in the editor, it needs to be annotated with the
  19. ``[Tool]`` attribute.
  20. .. code-block:: csharp
  21. :emphasize-lines: 1
  22. [Tool]
  23. public partial class MyNode : Node
  24. {
  25. [ExportToolButton("Click me!")]
  26. public Callable ClickMeButton => Callable.From(ClickMe);
  27. private static void ClickMe()
  28. {
  29. GD.Print("Hello world!");
  30. }
  31. }
  32. How to fix violations
  33. ---------------------
  34. To fix a violation of this rule, add the ``[Tool]`` attribute to the class that
  35. contains the member annotated with the ``[ExportToolButton]`` attribute.
  36. When to suppress warnings
  37. -------------------------
  38. Do not suppress a warning from this rule. The clickable buttons in the inspector
  39. won't be functional if their script is not annotated with the ``[Tool]`` attribute.