command_line_tutorial.rst 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. .. _doc_command_line_tutorial:
  2. Command line tutorial
  3. =====================
  4. .. highlight:: shell
  5. Some developers like using the command line extensively. Godot is
  6. designed to be friendly to them, so here are the steps for working
  7. entirely from the command line. Given the engine relies on almost no
  8. external libraries, initialization times are pretty fast, making it
  9. suitable for this workflow.
  10. Command line reference
  11. ----------------------
  12. **General options**
  13. +----------------------------+----------------------------------------------------------------------+
  14. | Command | Description |
  15. +----------------------------+----------------------------------------------------------------------+
  16. | ``-h``, ``--help``, ``/?`` | Display the list of command line options. |
  17. +----------------------------+----------------------------------------------------------------------+
  18. | ``--version`` | Display the version string. |
  19. +----------------------------+----------------------------------------------------------------------+
  20. | ``-v``, ``--verbose`` | Use verbose stdout mode. |
  21. +----------------------------+----------------------------------------------------------------------+
  22. | ``--quiet`` | Quiet mode, silences stdout messages. Errors are still displayed. |
  23. +----------------------------+----------------------------------------------------------------------+
  24. **Run options**
  25. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | Command | Description |
  27. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | ``-e``, ``--editor`` | Start the editor instead of running the scene (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  29. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | ``-p``, ``--project-manager`` | Start the project manager, even if a project is auto-detected (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  31. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | ``-q``, ``--quit`` | Quit after the first iteration. |
  33. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | ``-l <locale>``, ``--language <locale>`` | Use a specific locale (<locale> being a two-letter code). See :ref:`doc_locales` for more details. |
  35. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | ``--path <directory>`` | Path to a project (<directory> must contain a 'project.godot' file). |
  37. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | ``-u``, ``--upwards`` | Scan folders upwards for 'project.godot' file. |
  39. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | ``--main-pack <file>`` | Path to a pack (.pck) file to load. |
  41. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | ``--render-thread <mode>`` | Render thread mode ('unsafe', 'safe', 'separate'). See :ref:`Thread Model <class_ProjectSettings_property_rendering/threads/thread_model>` for more details. |
  43. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | ``--remote-fs <address>`` | Remote filesystem (``<host/IP>[:<port>]`` address). |
  45. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | ``--remote-fs-password <password>`` | Password for remote filesystem. |
  47. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | ``--audio-driver <driver>`` | Audio driver. Use ``--help`` first to display the list of available drivers. |
  49. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | ``--display-driver <driver>`` | Display driver (and rendering driver). Use ``--help`` first to display the list of available drivers. |
  51. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | ``--rendering-driver <driver>`` | Rendering driver (depends on display driver). Use ``--help`` first to display the list of available drivers. |
  53. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. **Display options**
  55. +------------------------------------+----------------------------------------------------------------------------+
  56. | Command | Description |
  57. +------------------------------------+----------------------------------------------------------------------------+
  58. | ``-f``, ``--fullscreen`` | Request fullscreen mode. |
  59. +------------------------------------+----------------------------------------------------------------------------+
  60. | ``-m``, ``--maximized`` | Request a maximized window. |
  61. +------------------------------------+----------------------------------------------------------------------------+
  62. | ``-w``, ``--windowed`` | Request windowed mode. |
  63. +------------------------------------+----------------------------------------------------------------------------+
  64. | ``-t``, ``--always-on-top`` | Request an always-on-top window. |
  65. +------------------------------------+----------------------------------------------------------------------------+
  66. | ``--resolution <W>x<H>`` | Request window resolution. |
  67. +------------------------------------+----------------------------------------------------------------------------+
  68. | ``--position <X>,<Y>`` | Request window position. |
  69. +------------------------------------+----------------------------------------------------------------------------+
  70. | ``--low-dpi`` | Force low-DPI mode (macOS and Windows only). |
  71. +------------------------------------+----------------------------------------------------------------------------+
  72. | ``--no-window`` | Disable window creation (Windows only). Useful together with ``--script``. |
  73. +------------------------------------+----------------------------------------------------------------------------+
  74. | ``--enable-vsync-via-compositor`` | When vsync is enabled, vsync via the OS' window compositor (Windows only). |
  75. +------------------------------------+----------------------------------------------------------------------------+
  76. | ``--disable-vsync-via-compositor`` | Disable vsync via the OS' window compositor (Windows only). |
  77. +------------------------------------+----------------------------------------------------------------------------+
  78. | ``--single-window`` | Use a single window (no separate subwindows). |
  79. +------------------------------------+----------------------------------------------------------------------------+
  80. | ``--tablet-driver`` | Tablet input driver (Windows only). |
  81. +------------------------------------+----------------------------------------------------------------------------+
  82. **Debug options**
  83. .. note::
  84. Debug options are only available in the editor and debug export templates
  85. (they require ``debug`` or ``release_debug`` build targets, see
  86. :ref:`doc_introduction_to_the_buildsystem_target` for more details).
  87. +------------------------------+---------------------------------------------------------------------------------------------------------+
  88. | Command | Description |
  89. +------------------------------+---------------------------------------------------------------------------------------------------------+
  90. | ``-d``, ``--debug`` | Debug (local stdout debugger). |
  91. +------------------------------+---------------------------------------------------------------------------------------------------------+
  92. | ``-b``, ``--breakpoints`` | Breakpoint list as source::line comma-separated pairs, no spaces (use %20 instead). |
  93. +------------------------------+---------------------------------------------------------------------------------------------------------+
  94. | ``--profiling`` | Enable profiling in the script debugger. |
  95. +------------------------------+---------------------------------------------------------------------------------------------------------+
  96. | ``--gpu-abort`` | Abort on GPU errors (usually validation layer errors), may help see the problem if your system freezes. |
  97. +------------------------------+---------------------------------------------------------------------------------------------------------+
  98. | ``--remote-debug <address>`` | Remote debug (<protocol>://<host/IP>[:<port>], e.g. tcp://127.0.0.1:6007). |
  99. +------------------------------+---------------------------------------------------------------------------------------------------------+
  100. | ``--debug-collisions`` | Show collision shapes when running the scene. |
  101. +------------------------------+---------------------------------------------------------------------------------------------------------+
  102. | ``--debug-navigation`` | Show navigation polygons when running the scene. |
  103. +------------------------------+---------------------------------------------------------------------------------------------------------+
  104. | ``--frame-delay <ms>`` | Simulate high CPU load (delay each frame by <ms> milliseconds). |
  105. +------------------------------+---------------------------------------------------------------------------------------------------------+
  106. | ``--time-scale <scale>`` | Force time scale (higher values are faster, 1.0 is normal speed). |
  107. +------------------------------+---------------------------------------------------------------------------------------------------------+
  108. | ``--disable-render-loop`` | Disable render loop so rendering only occurs when called explicitly from script. |
  109. +------------------------------+---------------------------------------------------------------------------------------------------------+
  110. | ``--disable-crash-handler`` | Disable crash handler when supported by the platform code. |
  111. +------------------------------+---------------------------------------------------------------------------------------------------------+
  112. | ``--fixed-fps <fps>`` | Force a fixed number of frames per second. This setting disables real-time synchronization. |
  113. +------------------------------+---------------------------------------------------------------------------------------------------------+
  114. | ``--print-fps`` | Print the frames per second to the stdout. |
  115. +------------------------------+---------------------------------------------------------------------------------------------------------+
  116. **Standalone tools**
  117. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | Command | Description |
  119. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | ``-s <script>``, ``--script <script>`` | Run a script. |
  121. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | ``--check-only`` | Only parse for errors and quit (use with ``--script``). |
  123. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | ``--export <preset> <path>`` | Export the project using the given export target. Export only main pack if path ends with .pck or .zip |
  125. | | (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  126. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  127. | ``--export-debug <preset> <path>`` | Like ``--export``, but use debug template (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  128. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  129. | ``--export-pack <preset> <path>`` | Like ``--export``, but only export the game pack for the given preset. The <path> extension determines whether it will be in PCK or ZIP format. |
  130. | | (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  131. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  132. | ``--doctool <path>`` | Dump the engine API reference to the given <path> in XML format, merging if existing files are found |
  133. | | (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  134. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  135. | ``--no-docbase`` | Disallow dumping the base types (used with ``--doctool``, :ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  136. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  137. | ``--build-solutions`` | Build the scripting solutions (e.g. for C# projects, :ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  138. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  139. | ``--gdnative-generate-json-api`` | Generate JSON dump of the Godot API for GDNative bindings (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  140. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  141. | ``--test <test>`` | Run a unit test. Use ``--help`` first to display the list of tests. (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  142. +----------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------+
  143. Path
  144. ----
  145. It is recommended that your Godot editor binary be in your ``PATH`` environment
  146. variable, so it can be executed easily from any place by typing ``godot``.
  147. You can do so on Linux by placing the Godot binary in ``/usr/local/bin`` and
  148. making sure it is called ``godot``.
  149. Setting the project path
  150. ------------------------
  151. Depending on where your Godot binary is located and what your current
  152. working directory is, you may need to set the path to your project
  153. for any of the following commands to work correctly.
  154. This can be done by giving the path to the ``project.godot`` file
  155. of your project as either the first argument, like this:
  156. ::
  157. godot path_to_your_project/project.godot [other] [commands] [and] [args]
  158. Or by using the ``--path`` argument:
  159. ::
  160. godot --path path_to_your_project [other] [commands] [and] [args]
  161. For example, the full command for exporting your game (as explained below) might look like this:
  162. ::
  163. godot --path path_to_your_project --export my_export_preset_name game.exe
  164. Creating a project
  165. ------------------
  166. Creating a project from the command line can be done by navigating the
  167. shell to the desired place and making a ``project.godot`` file.
  168. ::
  169. mkdir newgame
  170. cd newgame
  171. touch project.godot
  172. The project can now be opened with Godot.
  173. Running the editor
  174. ------------------
  175. Running the editor is done by executing Godot with the ``-e`` flag. This
  176. must be done from within the project directory or a subdirectory,
  177. otherwise the command is ignored and the project manager appears.
  178. ::
  179. godot -e
  180. If a scene has been created and saved, it can be edited later by running
  181. the same code with that scene as argument.
  182. ::
  183. godot -e scene.tscn
  184. Erasing a scene
  185. ---------------
  186. Godot is friends with your filesystem and will not create extra metadata files.
  187. Use ``rm`` to erase a scene file. Make sure nothing references that scene.
  188. Otherwise, an error will be thrown upon opening the project.
  189. ::
  190. rm scene.tscn
  191. Running the game
  192. ----------------
  193. To run the game, simply execute Godot within the project directory or
  194. subdirectory.
  195. ::
  196. godot
  197. When a specific scene needs to be tested, pass that scene to the command
  198. line.
  199. ::
  200. godot scene.tscn
  201. Debugging
  202. ---------
  203. Catching errors in the command line can be a difficult task because they
  204. scroll quickly. For this, a command line debugger is provided by adding
  205. ``-d``. It works for running either the game or a single scene.
  206. ::
  207. godot -d
  208. ::
  209. godot -d scene.tscn
  210. .. _doc_command_line_tutorial_exporting:
  211. Exporting
  212. ---------
  213. Exporting the project from the command line is also supported. This is
  214. especially useful for continuous integration setups. The version of Godot
  215. that is headless (server build, no video) is ideal for this.
  216. ::
  217. # `godot` must be a Godot editor binary, not an export template.
  218. # Also, export templates must be installed for the editor
  219. # (or a valid custom export template must be defined in the export preset).
  220. godot --export "Linux/X11" /var/builds/project
  221. godot --export Android /var/builds/project.apk
  222. The preset name must match the name of an export preset defined in the
  223. project's ``export_presets.cfg`` file. If the preset name contains spaces or
  224. special characters (such as "Windows Desktop"), it must be surrounded with quotes.
  225. To export a debug version of the game, use the ``--export-debug`` switch
  226. instead of ``--export``. Their parameters and usage are the same.
  227. To export only a PCK file, use the ``--export-pack`` option followed by the
  228. preset name and output path, with the file extension, instead of ``--export``.
  229. The output path extension determines the package's format, either PCK or ZIP.
  230. .. warning::
  231. When specifying a relative path as the path for `--export`, `--export-debug`
  232. or `--export-pack`, the path will be relative to the directory containing
  233. the ``project.godot`` file, **not** relative to the current working directory.
  234. Running a script
  235. ----------------
  236. It is possible to run a ``.gd`` script from the command line.
  237. This feature is especially useful in large projects, e.g. for batch
  238. conversion of assets or custom import/export.
  239. The script must inherit from ``SceneTree`` or ``MainLoop``.
  240. Here is an example ``sayhello.gd``, showing how it works:
  241. .. code-block:: python
  242. #!/usr/bin/env -S godot -s
  243. extends SceneTree
  244. func _init():
  245. print("Hello!")
  246. quit()
  247. And how to run it:
  248. ::
  249. # Prints "Hello!" to standard output.
  250. godot -s sayhello.gd
  251. If no ``project.godot`` exists at the path, current path is assumed to be the
  252. current working directory (unless ``--path`` is specified).
  253. The first line of ``sayhello.gd`` above is commonly referred to as
  254. a *shebang*. If the Godot binary is in your ``PATH`` as ``godot``,
  255. it allows you to run the script as follows in modern Linux
  256. distributions, as well as macOS:
  257. ::
  258. # Mark script as executable.
  259. chmod +x sayhello.gd
  260. # Prints "Hello!" to standard output.
  261. ./sayhello.gd
  262. If the above doesn't work in your current version of Linux or macOS, you can
  263. always have the shebang run Godot straight from where it is located as follows:
  264. ::
  265. #!/usr/bin/godot -s