data_paths.rst 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 make supporting multiple platforms easier, Godot only accepts UNIX-style path
  10. separators (``/``). 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.
  28. Unlike ``res://``, the directory pointed at by ``user://`` is *guaranteed* to be
  29. writable to, even in an exported project.
  30. On desktop platforms, the actual directory paths for ``user://`` are:
  31. +-------------------------------+------------------------------------------------------------------------------+
  32. | Type | Location |
  33. +===============================+==============================================================================+
  34. | User data | - Windows: ``%APPDATA%\Godot\app_userdata\[project_name]`` |
  35. | | - macOS: ``~/Library/Application Support/Godot/app_userdata/[project_name]`` |
  36. | | - Linux: ``~/.local/share/godot/app_userdata/[project_name]`` |
  37. +-------------------------------+------------------------------------------------------------------------------+
  38. | User data | - Windows: ``%APPDATA%\[project_name]`` |
  39. | (when ``use_custom_user_dir`` | - macOS: ``~/Library/Application Support/[project_name]`` |
  40. | project setting is ``true``) | - Linux: ``~/.local/share/[project_name]`` |
  41. +-------------------------------+------------------------------------------------------------------------------+
  42. ``[project_name]`` is based on the application name defined in the Project Settings, but
  43. you can override it on a per-platform basis using :ref:`feature tags <doc_feature_tags>`.
  44. On mobile platforms, this path is unique to the project and is not accessible
  45. by other applications for security reasons.
  46. On HTML5 exports, ``user://`` will refer to a virtual filesystem stored on the
  47. device via IndexedDB. (Interaction with the main filesystem can still be performed
  48. through the :ref:`JavaScript <class_JavaScript>` singleton.)
  49. Editor data paths
  50. -----------------
  51. The editor uses different paths for user data, user settings, and cache,
  52. depending on the platform. By default, these paths are:
  53. +-------------------------------+----------------------------------------------------------------+
  54. | Type | Location |
  55. +===============================+================================================================+
  56. | User data | - Windows: ``%APPDATA%\Godot\app_userdata\[project_name]`` |
  57. | | - macOS: ``~/Library/Application Support/Godot/[project_name]``|
  58. | | - Linux: ``~/.local/share/godot/[project_name]`` |
  59. +-------------------------------+----------------------------------------------------------------+
  60. | User data | - Windows: ``%APPDATA%\[project_name]`` |
  61. | (when ``use_custom_user_dir`` | - macOS: ``~/Library/Application Support/[project_name]`` |
  62. | project setting is ``true``) | - Linux: ``~/.local/share/[project_name]`` |
  63. +-------------------------------+----------------------------------------------------------------+
  64. | User settings | - Windows: ``%APPDATA%\Godot\`` |
  65. | | - macOS: ``~/Library/Application Support/Godot/`` |
  66. | | - Linux: ``~/.config/godot/`` |
  67. +-------------------------------+----------------------------------------------------------------+
  68. | Cache | - Windows: ``%TEMP%\Godot\`` |
  69. | | - macOS: ``~/Library/Caches/Godot/`` |
  70. | | - Linux: ``~/.cache/godot/`` |
  71. +-------------------------------+----------------------------------------------------------------+
  72. - **User data** contains export templates and project-specific data.
  73. - **User settings** contains editor settings, text editor themes, script
  74. templates, etc.
  75. - **Cache** contains temporary data. It can safely be removed when Godot is
  76. closed.
  77. Godot complies with the `XDG Base Directory Specification
  78. <https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html>`__
  79. on all platforms. You can override environment variables following the
  80. specification to change the editor and project data paths.
  81. .. note:: If you use `Godot packaged as a Flatpak
  82. <https://flathub.org/apps/details/org.godotengine.Godot>`__, the
  83. editor data paths will be located in subfolders in
  84. ``~/.var/app/org.godotengine.Godot/``.
  85. .. _doc_data_paths_self_contained_mode:
  86. Self-contained mode
  87. ~~~~~~~~~~~~~~~~~~~
  88. If you create a file called ``._sc_`` or ``_sc_`` in the same directory as the
  89. editor binary, Godot will enable *self-contained mode*. This mode makes Godot
  90. write all user data to a directory named ``editor_data/`` in the same directory
  91. as the editor binary. You can use it to create a portable installation of the
  92. editor.
  93. The `Steam release of Godot <https://store.steampowered.com/app/404790/>`__ uses
  94. self-contained mode by default.
  95. .. note::
  96. Self-contained mode is not supported in exported projects yet.
  97. To read and write files relative to the executable path, use
  98. :ref:`OS.get_executable_path() <class_OS_method_get_executable_path>`.
  99. Note that writing files in the executable path only works if the executable
  100. is placed in a writable location (i.e. **not** Program Files or another
  101. directory that is read-only for regular users).