filesystem.rst 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. .. _doc_filesystem:
  2. File system
  3. ===========
  4. Introduction
  5. ------------
  6. A file system manages how assets are stored and how they are accessed.
  7. A well-designed file system also allows multiple developers to edit the
  8. same source files and assets while collaborating. Godot stores
  9. all assets as files in its file system.
  10. Implementation
  11. --------------
  12. The file system stores resources on disk. Anything, from a script, to a scene or a
  13. PNG image is a resource to the engine. If a resource contains properties
  14. that reference other resources on disk, the paths to those resources are also
  15. included. If a resource has sub-resources that are built-in, the resource is
  16. saved in a single file together with all the bundled sub-resources. For
  17. example, a font resource is often bundled together with the font textures.
  18. The Godot file system avoids using metadata files. Existing asset managers and VCSs
  19. are better than anything we can implement, so Godot tries its best to play along
  20. with Subversion, Git, Mercurial, etc.
  21. Example of file system contents:
  22. .. code-block:: none
  23. /project.godot
  24. /enemy/enemy.tscn
  25. /enemy/enemy.gd
  26. /enemy/enemysprite.png
  27. /player/player.gd
  28. project.godot
  29. -------------
  30. The ``project.godot`` file is the project description file, and it is always found
  31. at the root of the project. In fact, its location defines where the root is. This
  32. is the first file that Godot looks for when opening a project.
  33. This file contains the project configuration in plain text, using the win.ini
  34. format. Even an empty ``project.godot`` can function as a basic definition of
  35. a blank project.
  36. Path delimiter
  37. --------------
  38. Godot only supports ``/`` as a path delimiter. This is done for
  39. portability reasons. All operating systems support this, even Windows,
  40. so a path such as ``C:\project\project.godot`` needs to be typed as
  41. ``C:/project/project.godot``.
  42. Resource path
  43. -------------
  44. When accessing resources, using the host OS file system layout can be
  45. cumbersome and non-portable. To solve this problem, the special path
  46. ``res://`` was created.
  47. The path ``res://`` will always point at the project root (where
  48. ``project.godot`` is located, so ``res://project.godot`` is always
  49. valid).
  50. This file system is read-write only when running the project locally from
  51. the editor. When exported or when running on different devices (such as
  52. phones or consoles, or running from DVD), the file system will become
  53. read-only and writing will no longer be permitted.
  54. User path
  55. ---------
  56. Writing to disk is still needed for tasks such as saving game state or
  57. downloading content packs. To this end, the engine ensures that there is a
  58. special path ``user://`` that is always writable. This path resolves
  59. differently depending on the OS the project is running on. Local path
  60. resolution is further explained in :ref:`doc_data_paths`.
  61. Host file system
  62. ----------------
  63. Alternatively host file system paths can also be used, but this is not recommended
  64. for a released product as these paths are not guaranteed to work on all platforms.
  65. However, using host file system paths can be useful when writing development
  66. tools in Godot.
  67. Drawbacks
  68. ---------
  69. There are some drawbacks to this file system design. The first issue is that
  70. moving assets around (renaming them or moving them from one path to another inside
  71. the project) will break existing references to these assets. These references will
  72. have to be re-defined to point at the new asset location.
  73. To avoid this, do all your move, delete and rename operations from within Godot, on
  74. the FileSystem dock. Never move assets from outside Godot, or dependencies will have
  75. to be fixed manually (Godot detects this and helps you fix them anyway, but why
  76. go the hard route?).
  77. The second is that, under Windows and macOS, file and path names are case insensitive.
  78. If a developer working in a case insensitive host file system saves an asset as ``myfile.PNG``,
  79. but then references it as ``myfile.png``, it will work fine on their platform, but not
  80. on other platforms, such as Linux, Android, etc. This may also apply to exported binaries,
  81. which use a compressed package to store all files.
  82. It is recommended that your team clearly define a naming convention for files when
  83. working with Godot. One fool-proof convention is to only allow lowercase
  84. file and path names.