filesystem.rst 4.5 KB

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