class_editorscript.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.0/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.0/doc/classes/EditorScript.xml.
  6. .. _class_EditorScript:
  7. EditorScript
  8. ============
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. Base script that can be used to add extension functions to the editor.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. Scripts extending this class and implementing its :ref:`_run<class_EditorScript_method__run>` method can be executed from the Script Editor's **File > Run** menu option (or by pressing :kbd:`Ctrl + Shift + X`) while the editor is running. This is useful for adding custom in-editor functionality to Godot. For more complex additions, consider using :ref:`EditorPlugin<class_EditorPlugin>`\ s instead.
  15. \ **Note:** Extending scripts need to have ``tool`` mode enabled.
  16. \ **Example script:**\
  17. .. tabs::
  18. .. code-tab:: gdscript
  19. @tool
  20. extends EditorScript
  21. func _run():
  22. print("Hello from the Godot Editor!")
  23. .. code-tab:: csharp
  24. using Godot;
  25. [Tool]
  26. public partial class HelloEditor : EditorScript
  27. {
  28. public override void _Run()
  29. {
  30. GD.Print("Hello from the Godot Editor!");
  31. }
  32. }
  33. \ **Note:** The script is run in the Editor context, which means the output is visible in the console window started with the Editor (stdout) instead of the usual Godot **Output** dock.
  34. \ **Note:** EditorScript is :ref:`RefCounted<class_RefCounted>`, meaning it is destroyed when nothing references it. This can cause errors during asynchronous operations if there are no references to the script.
  35. .. rst-class:: classref-reftable-group
  36. Methods
  37. -------
  38. .. table::
  39. :widths: auto
  40. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  41. | void | :ref:`_run<class_EditorScript_method__run>` **(** **)** |virtual| |
  42. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`add_root_node<class_EditorScript_method_add_root_node>` **(** :ref:`Node<class_Node>` node **)** |
  44. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  45. | :ref:`EditorInterface<class_EditorInterface>` | :ref:`get_editor_interface<class_EditorScript_method_get_editor_interface>` **(** **)** |
  46. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  47. | :ref:`Node<class_Node>` | :ref:`get_scene<class_EditorScript_method_get_scene>` **(** **)** |
  48. +-----------------------------------------------+--------------------------------------------------------------------------------------------------------+
  49. .. rst-class:: classref-section-separator
  50. ----
  51. .. rst-class:: classref-descriptions-group
  52. Method Descriptions
  53. -------------------
  54. .. _class_EditorScript_method__run:
  55. .. rst-class:: classref-method
  56. void **_run** **(** **)** |virtual|
  57. This method is executed by the Editor when **File > Run** is used.
  58. .. rst-class:: classref-item-separator
  59. ----
  60. .. _class_EditorScript_method_add_root_node:
  61. .. rst-class:: classref-method
  62. void **add_root_node** **(** :ref:`Node<class_Node>` node **)**
  63. Adds ``node`` as a child of the root node in the editor context.
  64. \ **Warning:** The implementation of this method is currently disabled.
  65. .. rst-class:: classref-item-separator
  66. ----
  67. .. _class_EditorScript_method_get_editor_interface:
  68. .. rst-class:: classref-method
  69. :ref:`EditorInterface<class_EditorInterface>` **get_editor_interface** **(** **)**
  70. Returns the :ref:`EditorInterface<class_EditorInterface>` singleton instance.
  71. .. rst-class:: classref-item-separator
  72. ----
  73. .. _class_EditorScript_method_get_scene:
  74. .. rst-class:: classref-method
  75. :ref:`Node<class_Node>` **get_scene** **(** **)**
  76. Returns the Editor's currently active scene.
  77. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  78. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  79. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  80. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  81. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  82. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`