data_paths.rst 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. .. _doc_data_paths:
  2. File paths in Godot projects
  3. ============================
  4. This page explains how file paths work inside Godot projects. You will learn how
  5. to access paths in your projects using the ``res://`` and ``user://`` notations
  6. and where Godot stores user files on your hard-drive.
  7. Path separators
  8. ---------------
  9. To as many platforms as possible, Godot only accepts UNIX-style path separators
  10. (``/``). These work on all platforms, including Windows.
  11. Instead of writing paths like ``C:\Projects``, in Godot, you should write
  12. ``C:/Projects``.
  13. Accessing files in the project folder
  14. -------------------------------------
  15. Godot considers that a project exists in any folder that contains a
  16. ``project.godot`` text file, even if the file is empty. The folder that contains
  17. this file is your project's root folder.
  18. You can access any file relative to it by writing paths starting with
  19. ``res://``, which stands for resources. For example, you can access an image
  20. file ``character.png`` located in the project's root folder in code with the
  21. following path: ``res://character.png``.
  22. Accessing persistent user data
  23. ------------------------------
  24. To store persistent data files, like the player's save or settings, you want to
  25. use ``user://`` instead of ``res://`` as your path's prefix. This is because
  26. when the game is running, the project's file system will likely be read-only.
  27. The ``user://`` prefix points to a different directory on the user's device. On
  28. mobile and consoles, this path is unique to the project. On desktop, the engine
  29. stores user files in ``~/.local/share/godot/app_userdata/[project_name]`` on
  30. Linux, ``~/Library/Application Support/Godot/app_userdata/[project_name]`` on
  31. macOS (since Catalina) and ``%APPDATA%\Godot\app_userdata\[project_name]`` on Windows.
  32. ``[project_name]`` is based on the application name defined in the Project Settings, but
  33. you can override it on a per-platform basis using :ref:`feature tags <doc_feature_tags>`.
  34. On HTML5 exports, ``user://`` will refer to a virtual filesystem stored on the
  35. device via IndexedDB. (Interaction with the main filesystem can still be performed
  36. through the :ref:`JavaScript <class_JavaScript>` singleton.)
  37. Converting paths to absolute paths or "local" paths
  38. ---------------------------------------------------
  39. You can use :ref:`ProjectSettings.globalize_path() <class_ProjectSettings_method_globalize_path>`
  40. to convert a "local" path like ``res://path/to/file.txt`` to an absolute OS path.
  41. For example, :ref:`ProjectSettings.globalize_path() <class_ProjectSettings_method_globalize_path>`
  42. can be used to open "local" paths in the OS file manager
  43. using :ref:`OS.shell_open() <class_OS_method_shell_open>` since it only accepts
  44. native OS paths.
  45. To convert an absolute OS path to a "local" path starting with ``res://``, use
  46. :ref:`ProjectSettings.localize_path() <class_ProjectSettings_method_localize_path>`.
  47. Editor data paths
  48. -----------------
  49. The editor uses different paths for user data, user settings, and cache,
  50. depending on the platform. By default, these paths are:
  51. +-------------------------------+----------------------------------------------------------------+
  52. | Type | Location |
  53. +===============================+================================================================+
  54. | User data | - Windows: ``%APPDATA%\Godot\app_userdata\[project_name]`` |
  55. | | - macOS: ``~/Library/Application Support/Godot/[project_name]``|
  56. | | - Linux: ``~/.local/share/godot/[project_name]`` |
  57. +-------------------------------+----------------------------------------------------------------+
  58. | User data | - Windows: ``%APPDATA%\[project_name]`` |
  59. | (when ``use_custom_user_dir`` | - macOS: ``~/Library/Application Support/[project_name]`` |
  60. | project setting is ``true``) | - Linux: ``~/.local/share/[project_name]`` |
  61. +-------------------------------+----------------------------------------------------------------+
  62. | User settings | - Windows: ``%APPDATA%\Godot\`` |
  63. | | - macOS: ``~/Library/Application Support/Godot/`` |
  64. | | - Linux: ``~/.config/godot/`` |
  65. +-------------------------------+----------------------------------------------------------------+
  66. | Cache | - Windows: ``%TEMP%\Godot\`` |
  67. | | - macOS: ``~/Library/Caches/Godot/`` |
  68. | | - Linux: ``~/.cache/godot/`` |
  69. +-------------------------------+----------------------------------------------------------------+
  70. - **User data** contains export templates and project-specific data.
  71. - **User settings** contains editor settings, text editor themes, script
  72. templates, etc.
  73. - **Cache** contains temporary data. It can safely be removed when Godot is
  74. closed.
  75. Godot complies with the `XDG Base Directory Specification
  76. <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html>`__
  77. on all platforms. You can override environment variables following the
  78. specification to change the editor and project data paths.
  79. .. note:: If you use `Godot packaged as a Flatpak
  80. <https://flathub.org/apps/details/org.godotengine.Godot>`__, the
  81. editor data paths will be located in subfolders in
  82. ``~/.var/app/org.godotengine.Godot/``.
  83. .. _doc_data_paths_self_contained_mode:
  84. Self-contained mode
  85. ~~~~~~~~~~~~~~~~~~~
  86. If you create a file called ``._sc_`` or ``_sc_`` in the same directory as the
  87. editor binary, Godot will enable *self-contained mode*. This mode makes Godot
  88. write all user data to a directory named ``editor_data/`` in the same directory
  89. as the editor binary. You can use it to create a portable installation of the
  90. editor.
  91. The `Steam release of Godot <https://store.steampowered.com/app/404790/>`__ uses
  92. self-contained mode by default.