command_line_tutorial.rst 30 KB

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