command_line_tutorial.rst 25 KB

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