2
0

class_engine.rst 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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/3.6/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/3.6/doc/classes/Engine.xml.
  6. .. _class_Engine:
  7. Engine
  8. ======
  9. **Inherits:** :ref:`Object<class_Object>`
  10. Access to engine properties.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. The **Engine** singleton allows you to query and modify the project's run-time parameters, such as frames per second, time scale, and others.
  15. .. rst-class:: classref-reftable-group
  16. Properties
  17. ----------
  18. .. table::
  19. :widths: auto
  20. +---------------------------+---------------------------------------------------------------------------+----------+
  21. | :ref:`bool<class_bool>` | :ref:`editor_hint<class_Engine_property_editor_hint>` | ``true`` |
  22. +---------------------------+---------------------------------------------------------------------------+----------+
  23. | :ref:`int<class_int>` | :ref:`iterations_per_second<class_Engine_property_iterations_per_second>` | ``60`` |
  24. +---------------------------+---------------------------------------------------------------------------+----------+
  25. | :ref:`float<class_float>` | :ref:`physics_jitter_fix<class_Engine_property_physics_jitter_fix>` | ``0.5`` |
  26. +---------------------------+---------------------------------------------------------------------------+----------+
  27. | :ref:`bool<class_bool>` | :ref:`print_error_messages<class_Engine_property_print_error_messages>` | ``true`` |
  28. +---------------------------+---------------------------------------------------------------------------+----------+
  29. | :ref:`int<class_int>` | :ref:`target_fps<class_Engine_property_target_fps>` | ``0`` |
  30. +---------------------------+---------------------------------------------------------------------------+----------+
  31. | :ref:`float<class_float>` | :ref:`time_scale<class_Engine_property_time_scale>` | ``1.0`` |
  32. +---------------------------+---------------------------------------------------------------------------+----------+
  33. .. rst-class:: classref-reftable-group
  34. Methods
  35. -------
  36. .. table::
  37. :widths: auto
  38. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_author_info<class_Engine_method_get_author_info>` **(** **)** |const| |
  40. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`Array<class_Array>` | :ref:`get_copyright_info<class_Engine_method_get_copyright_info>` **(** **)** |const| |
  42. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_donor_info<class_Engine_method_get_donor_info>` **(** **)** |const| |
  44. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`int<class_int>` | :ref:`get_frames_drawn<class_Engine_method_get_frames_drawn>` **(** **)** |
  46. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`float<class_float>` | :ref:`get_frames_per_second<class_Engine_method_get_frames_per_second>` **(** **)** |const| |
  48. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`int<class_int>` | :ref:`get_idle_frames<class_Engine_method_get_idle_frames>` **(** **)** |const| |
  50. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_license_info<class_Engine_method_get_license_info>` **(** **)** |const| |
  52. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`String<class_String>` | :ref:`get_license_text<class_Engine_method_get_license_text>` **(** **)** |const| |
  54. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`MainLoop<class_MainLoop>` | :ref:`get_main_loop<class_Engine_method_get_main_loop>` **(** **)** |const| |
  56. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`get_physics_frames<class_Engine_method_get_physics_frames>` **(** **)** |const| |
  58. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`float<class_float>` | :ref:`get_physics_interpolation_fraction<class_Engine_method_get_physics_interpolation_fraction>` **(** **)** |const| |
  60. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Object<class_Object>` | :ref:`get_singleton<class_Engine_method_get_singleton>` **(** :ref:`String<class_String>` name **)** |const| |
  62. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Dictionary<class_Dictionary>` | :ref:`get_version_info<class_Engine_method_get_version_info>` **(** **)** |const| |
  64. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`has_singleton<class_Engine_method_has_singleton>` **(** :ref:`String<class_String>` name **)** |const| |
  66. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`bool<class_bool>` | :ref:`is_in_physics_frame<class_Engine_method_is_in_physics_frame>` **(** **)** |const| |
  68. +-------------------------------------+-----------------------------------------------------------------------------------------------------------------------+
  69. .. rst-class:: classref-section-separator
  70. ----
  71. .. rst-class:: classref-descriptions-group
  72. Property Descriptions
  73. ---------------------
  74. .. _class_Engine_property_editor_hint:
  75. .. rst-class:: classref-property
  76. :ref:`bool<class_bool>` **editor_hint** = ``true``
  77. .. rst-class:: classref-property-setget
  78. - void **set_editor_hint** **(** :ref:`bool<class_bool>` value **)**
  79. - :ref:`bool<class_bool>` **is_editor_hint** **(** **)**
  80. If ``true``, the script is currently running inside the editor. This is useful for ``tool`` scripts to conditionally draw editor helpers, or prevent accidentally running "game" code that would affect the scene state while in the editor:
  81. ::
  82. if Engine.editor_hint:
  83. draw_gizmos()
  84. else:
  85. simulate_physics()
  86. See :doc:`Running code in the editor <../tutorials/plugins/running_code_in_the_editor>` in the documentation for more information.
  87. \ **Note:** To detect whether the script is run from an editor *build* (e.g. when pressing ``F5``), use :ref:`OS.has_feature<class_OS_method_has_feature>` with the ``"editor"`` argument instead. ``OS.has_feature("editor")`` will evaluate to ``true`` both when the code is running in the editor and when running the project from the editor, but it will evaluate to ``false`` when the code is run from an exported project.
  88. .. rst-class:: classref-item-separator
  89. ----
  90. .. _class_Engine_property_iterations_per_second:
  91. .. rst-class:: classref-property
  92. :ref:`int<class_int>` **iterations_per_second** = ``60``
  93. .. rst-class:: classref-property-setget
  94. - void **set_iterations_per_second** **(** :ref:`int<class_int>` value **)**
  95. - :ref:`int<class_int>` **get_iterations_per_second** **(** **)**
  96. The number of fixed iterations per second. This controls how often physics simulation and :ref:`Node._physics_process<class_Node_method__physics_process>` methods are run. This value should generally always be set to ``60`` or above, as Godot doesn't interpolate the physics step. As a result, values lower than ``60`` will look stuttery. This value can be increased to make input more reactive or work around collision tunneling issues, but keep in mind doing so will increase CPU usage. See also :ref:`target_fps<class_Engine_property_target_fps>` and :ref:`ProjectSettings.physics/common/physics_fps<class_ProjectSettings_property_physics/common/physics_fps>`.
  97. \ **Note:** Only 8 physics ticks may be simulated per rendered frame at most. If more than 8 physics ticks have to be simulated per rendered frame to keep up with rendering, the game will appear to slow down (even if ``delta`` is used consistently in physics calculations). Therefore, it is recommended not to increase :ref:`iterations_per_second<class_Engine_property_iterations_per_second>` above 240. Otherwise, the game will slow down when the rendering framerate goes below 30 FPS.
  98. .. rst-class:: classref-item-separator
  99. ----
  100. .. _class_Engine_property_physics_jitter_fix:
  101. .. rst-class:: classref-property
  102. :ref:`float<class_float>` **physics_jitter_fix** = ``0.5``
  103. .. rst-class:: classref-property-setget
  104. - void **set_physics_jitter_fix** **(** :ref:`float<class_float>` value **)**
  105. - :ref:`float<class_float>` **get_physics_jitter_fix** **(** **)**
  106. Controls how much physics ticks are synchronized with real time. For 0 or less, the ticks are synchronized. Such values are recommended for network games, where clock synchronization matters. Higher values cause higher deviation of the in-game clock and real clock but smooth out framerate jitters. The default value of 0.5 should be fine for most; values above 2 could cause the game to react to dropped frames with a noticeable delay and are not recommended.
  107. \ **Note:** For best results, when using a custom physics interpolation solution, the physics jitter fix should be disabled by setting :ref:`physics_jitter_fix<class_Engine_property_physics_jitter_fix>` to ``0``.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. _class_Engine_property_print_error_messages:
  111. .. rst-class:: classref-property
  112. :ref:`bool<class_bool>` **print_error_messages** = ``true``
  113. .. rst-class:: classref-property-setget
  114. - void **set_print_error_messages** **(** :ref:`bool<class_bool>` value **)**
  115. - :ref:`bool<class_bool>` **is_printing_error_messages** **(** **)**
  116. If ``false``, stops printing error and warning messages to the console and editor Output log. This can be used to hide error and warning messages during unit test suite runs. This property is equivalent to the :ref:`ProjectSettings.application/run/disable_stderr<class_ProjectSettings_property_application/run/disable_stderr>` project setting.
  117. \ **Warning:** If you set this to ``false`` anywhere in the project, important error messages may be hidden even if they are emitted from other scripts. If this is set to ``false`` in a ``tool`` script, this will also impact the editor itself. Do *not* report bugs before ensuring error messages are enabled (as they are by default).
  118. \ **Note:** This property does not impact the editor's Errors tab when running a project from the editor.
  119. .. rst-class:: classref-item-separator
  120. ----
  121. .. _class_Engine_property_target_fps:
  122. .. rst-class:: classref-property
  123. :ref:`int<class_int>` **target_fps** = ``0``
  124. .. rst-class:: classref-property-setget
  125. - void **set_target_fps** **(** :ref:`int<class_int>` value **)**
  126. - :ref:`int<class_int>` **get_target_fps** **(** **)**
  127. The desired frames per second. If the hardware cannot keep up, this setting may not be respected. A value of 0 means no limit.
  128. .. rst-class:: classref-item-separator
  129. ----
  130. .. _class_Engine_property_time_scale:
  131. .. rst-class:: classref-property
  132. :ref:`float<class_float>` **time_scale** = ``1.0``
  133. .. rst-class:: classref-property-setget
  134. - void **set_time_scale** **(** :ref:`float<class_float>` value **)**
  135. - :ref:`float<class_float>` **get_time_scale** **(** **)**
  136. Controls how fast or slow the in-game clock ticks versus the real life one. It defaults to 1.0. A value of 2.0 means the game moves twice as fast as real life, whilst a value of 0.5 means the game moves at half the regular speed. This also affects :ref:`Timer<class_Timer>` and :ref:`SceneTreeTimer<class_SceneTreeTimer>` (see :ref:`SceneTree.create_timer<class_SceneTree_method_create_timer>` for how to control this).
  137. .. rst-class:: classref-section-separator
  138. ----
  139. .. rst-class:: classref-descriptions-group
  140. Method Descriptions
  141. -------------------
  142. .. _class_Engine_method_get_author_info:
  143. .. rst-class:: classref-method
  144. :ref:`Dictionary<class_Dictionary>` **get_author_info** **(** **)** |const|
  145. Returns engine author information in a Dictionary.
  146. \ ``lead_developers`` - Array of Strings, lead developer names
  147. \ ``founders`` - Array of Strings, founder names
  148. \ ``project_managers`` - Array of Strings, project manager names
  149. \ ``developers`` - Array of Strings, developer names
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_Engine_method_get_copyright_info:
  153. .. rst-class:: classref-method
  154. :ref:`Array<class_Array>` **get_copyright_info** **(** **)** |const|
  155. Returns an Array of copyright information Dictionaries.
  156. \ ``name`` - String, component name
  157. \ ``parts`` - Array of Dictionaries {``files``, ``copyright``, ``license``} describing subsections of the component
  158. .. rst-class:: classref-item-separator
  159. ----
  160. .. _class_Engine_method_get_donor_info:
  161. .. rst-class:: classref-method
  162. :ref:`Dictionary<class_Dictionary>` **get_donor_info** **(** **)** |const|
  163. Returns a Dictionary of Arrays of donor names.
  164. {``platinum_sponsors``, ``gold_sponsors``, ``silver_sponsors``, ``bronze_sponsors``, ``mini_sponsors``, ``gold_donors``, ``silver_donors``, ``bronze_donors``}
  165. .. rst-class:: classref-item-separator
  166. ----
  167. .. _class_Engine_method_get_frames_drawn:
  168. .. rst-class:: classref-method
  169. :ref:`int<class_int>` **get_frames_drawn** **(** **)**
  170. Returns the total number of frames drawn. On headless platforms, or if the render loop is disabled with ``--disable-render-loop`` via command line, :ref:`get_frames_drawn<class_Engine_method_get_frames_drawn>` always returns ``0``. See :ref:`get_idle_frames<class_Engine_method_get_idle_frames>`.
  171. .. rst-class:: classref-item-separator
  172. ----
  173. .. _class_Engine_method_get_frames_per_second:
  174. .. rst-class:: classref-method
  175. :ref:`float<class_float>` **get_frames_per_second** **(** **)** |const|
  176. Returns the frames per second of the running game.
  177. .. rst-class:: classref-item-separator
  178. ----
  179. .. _class_Engine_method_get_idle_frames:
  180. .. rst-class:: classref-method
  181. :ref:`int<class_int>` **get_idle_frames** **(** **)** |const|
  182. Returns the total number of frames passed since engine initialization which is advanced on each **idle frame**, regardless of whether the render loop is enabled. See also :ref:`get_frames_drawn<class_Engine_method_get_frames_drawn>` and :ref:`get_physics_frames<class_Engine_method_get_physics_frames>`.
  183. \ :ref:`get_idle_frames<class_Engine_method_get_idle_frames>` can be used to run expensive logic less often without relying on a :ref:`Timer<class_Timer>`:
  184. ::
  185. func _process(_delta):
  186. if Engine.get_idle_frames() % 2 == 0:
  187. pass # Run expensive logic only once every 2 idle (render) frames here.
  188. .. rst-class:: classref-item-separator
  189. ----
  190. .. _class_Engine_method_get_license_info:
  191. .. rst-class:: classref-method
  192. :ref:`Dictionary<class_Dictionary>` **get_license_info** **(** **)** |const|
  193. Returns Dictionary of licenses used by Godot and included third party components.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_Engine_method_get_license_text:
  197. .. rst-class:: classref-method
  198. :ref:`String<class_String>` **get_license_text** **(** **)** |const|
  199. Returns Godot license text.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_Engine_method_get_main_loop:
  203. .. rst-class:: classref-method
  204. :ref:`MainLoop<class_MainLoop>` **get_main_loop** **(** **)** |const|
  205. Returns the main loop object (see :ref:`MainLoop<class_MainLoop>` and :ref:`SceneTree<class_SceneTree>`).
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_Engine_method_get_physics_frames:
  209. .. rst-class:: classref-method
  210. :ref:`int<class_int>` **get_physics_frames** **(** **)** |const|
  211. Returns the total number of frames passed since engine initialization which is advanced on each **physics frame**. See also :ref:`get_idle_frames<class_Engine_method_get_idle_frames>`.
  212. \ :ref:`get_physics_frames<class_Engine_method_get_physics_frames>` can be used to run expensive logic less often without relying on a :ref:`Timer<class_Timer>`:
  213. ::
  214. func _physics_process(_delta):
  215. if Engine.get_physics_frames() % 2 == 0:
  216. pass # Run expensive logic only once every 2 physics frames here.
  217. .. rst-class:: classref-item-separator
  218. ----
  219. .. _class_Engine_method_get_physics_interpolation_fraction:
  220. .. rst-class:: classref-method
  221. :ref:`float<class_float>` **get_physics_interpolation_fraction** **(** **)** |const|
  222. Returns the fraction through the current physics tick we are at the time of rendering the frame. This can be used to implement fixed timestep interpolation.
  223. .. rst-class:: classref-item-separator
  224. ----
  225. .. _class_Engine_method_get_singleton:
  226. .. rst-class:: classref-method
  227. :ref:`Object<class_Object>` **get_singleton** **(** :ref:`String<class_String>` name **)** |const|
  228. Returns a global singleton with given ``name``. Often used for plugins, e.g. ``GodotPayment`` on Android.
  229. .. rst-class:: classref-item-separator
  230. ----
  231. .. _class_Engine_method_get_version_info:
  232. .. rst-class:: classref-method
  233. :ref:`Dictionary<class_Dictionary>` **get_version_info** **(** **)** |const|
  234. Returns the current engine version information in a Dictionary.
  235. \ ``major`` - Holds the major version number as an int
  236. \ ``minor`` - Holds the minor version number as an int
  237. \ ``patch`` - Holds the patch version number as an int
  238. \ ``hex`` - Holds the full version number encoded as a hexadecimal int with one byte (2 places) per number (see example below)
  239. \ ``status`` - Holds the status (e.g. "beta", "rc1", "rc2", ... "stable") as a String
  240. \ ``build`` - Holds the build name (e.g. "custom_build") as a String
  241. \ ``hash`` - Holds the full Git commit hash as a String
  242. \ ``year`` - Holds the year the version was released in as an int
  243. \ ``string`` - ``major`` + ``minor`` + ``patch`` + ``status`` + ``build`` in a single String
  244. The ``hex`` value is encoded as follows, from left to right: one byte for the major, one byte for the minor, one byte for the patch version. For example, "3.1.12" would be ``0x03010C``. **Note:** It's still an int internally, and printing it will give you its decimal representation, which is not particularly meaningful. Use hexadecimal literals for easy version comparisons from code:
  245. ::
  246. if Engine.get_version_info().hex >= 0x030200:
  247. # Do things specific to version 3.2 or later
  248. else:
  249. # Do things specific to versions before 3.2
  250. .. rst-class:: classref-item-separator
  251. ----
  252. .. _class_Engine_method_has_singleton:
  253. .. rst-class:: classref-method
  254. :ref:`bool<class_bool>` **has_singleton** **(** :ref:`String<class_String>` name **)** |const|
  255. Returns ``true`` if a singleton with given ``name`` exists in global scope.
  256. .. rst-class:: classref-item-separator
  257. ----
  258. .. _class_Engine_method_is_in_physics_frame:
  259. .. rst-class:: classref-method
  260. :ref:`bool<class_bool>` **is_in_physics_frame** **(** **)** |const|
  261. Returns ``true`` if the game is inside the fixed process and physics phase of the game loop.
  262. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  263. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  264. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  265. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`