filesystem.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 are better than
  19. anything we can implement, so Godot tries its best to play along with SVN,
  20. Git, Mercurial, Perforce, etc.
  21. Example of file system contents:
  22. ::
  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 at
  31. 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 a blank
  35. 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
  57. state or downloading content packs. To this end, the engine ensures that there is a
  58. special path ``user://`` that is always writable.
  59. Host file system
  60. ----------------
  61. Alternatively host file system paths can also be used, but this is not recommended
  62. for a released product as these paths are not guaranteed to work on all platforms.
  63. However, using host file system paths can be useful when writing development
  64. tools in Godot.
  65. Drawbacks
  66. ---------
  67. There are some drawbacks to this simple file system design. The first issue is that
  68. moving assets around (renaming them or moving them from one path to another inside
  69. the project) will break existing references to these assets. These references will
  70. have to be re-defined to point at the new asset location.
  71. To avoid this, do all your move, delete and rename operations from within Godot, on the FileSystem
  72. dock. Never move assets from outside Godot, or dependencies will have to be
  73. fixed manually (Godot detects this and helps you fix them anyway, but why
  74. go the hard route?).
  75. The second is that, under Windows and macOS, file and path names are case insensitive.
  76. If a developer working in a case insensitive host file system saves an asset as "myfile.PNG",
  77. but then references it as "myfile.png", it will work fine on their platform, but not
  78. on other platforms, such as Linux, Android, etc. This may also apply to exported binaries,
  79. which use a compressed package to store all files.
  80. It is recommended that your team clearly define a naming convention for files when
  81. working with Godot. One simple fool-proof convention is to only allow lowercase
  82. file and path names.