Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

System plików

Wprowadzenie

A file system manages how assets are stored and how they are accessed. A well-designed file system also allows multiple developers to edit the same source files and assets while collaborating. Godot stores all assets as files in its file system.

Implementacja

System plików przechowuje zasoby na dysku. Wszystko, od skryptu, po scenę lub obraz PNG, jest zasobem dla silnika. Jeśli zasób zawiera właściwości, które odnoszą się do innych zasobów na dysku, ścieżki do tych zasobów są również dołączone. Jeśli zasób posiada wbudowane pod-zasoby, to jest on zapisywany w jednym pliku wraz ze wszystkimi dołączonymi pod-zasobami. Na przykład zasób czcionki jest często łączony z teksturami czcionki.

The Godot file system avoids using metadata files. Existing asset managers and VCSs are better than anything we can implement, so Godot tries its best to play along with Subversion, Git, Mercurial, etc.

Example of file system contents:

/project.godot
/enemy/enemy.tscn
/enemy/enemy.gd
/enemy/enemysprite.png
/player/player.gd

projekt.godot

The project.godot file is the project description file, and it is always found at the root of the project. In fact, its location defines where the root is. This is the first file that Godot looks for when opening a project.

This file contains the project configuration in plain text, using the win.ini format. Even an empty project.godot can function as a basic definition of a blank project.

Path delimiter

Godot only supports / as a path delimiter. This is done for portability reasons. All operating systems support this, even Windows, so a path such as C:\project\project.godot needs to be typed as C:/project/project.godot.

Ścieżka zasobu

Uzyskując dostęp do zasobów, korzystanie z systemu plików OS hosta może być kłopotliwe i nieporęczne. W celu rozwiązania tego problemu utworzono specjalną ścieżkę res://.

The path res:// will always point at the project root (where project.godot is located, so res://project.godot is always valid).

Ten system plików jest odczytywany/zapisywany tylko wtedy, gdy projekt jest uruchamiany lokalnie z edytora. Po wyeksportowaniu lub uruchomieniu na różnych urządzeniach (takich jak telefony, konsole lub płyty DVD) system plików stanie się tylko do odczytu i zapis nie będzie już dozwolony.

Ścieżka użytkownika

Writing to disk is still needed for tasks such as saving game state or downloading content packs. To this end, the engine ensures that there is a special path user:// that is always writable. This path resolves differently depending on the OS the project is running on. Local path resolution is further explained in File paths in Godot projects.

System plików hosta

Alternatywnie można również wykorzystać ścieżki systemu plików hosta, ale nie jest to zalecane w przypadku produktów dopuszczonych do obrotu, ponieważ nie ma gwarancji, że ścieżki te będą działać na wszystkich platformach. Jednak używanie ścieżek systemowych hostów plików może być przydatne podczas pisania narzędzi programistycznych w Godot.

Wady

There are some drawbacks to this file system design. The first issue is that moving assets around (renaming them or moving them from one path to another inside the project) will break existing references to these assets. These references will have to be re-defined to point at the new asset location.

Aby tego uniknąć, wykonaj wszystkie operacje przenoszenia, usuwania i zmiany nazw z poziomu Godota w panelu na systemie plików. Nigdy nie przenoś zasobów spoza Godota, ponieważ jego błędne zależności będą musiały być naprawione ręcznie (Godot wykrywa to i pomaga naprawić je tak czy inaczej, ale czemu sobie życie utrudniać?).

The second is that, under Windows and macOS, file and path names are case insensitive. If a developer working in a case insensitive host file system saves an asset as myfile.PNG, but then references it as myfile.png, it will work fine on their platform, but not on other platforms, such as Linux, Android, etc. This may also apply to exported binaries, which use a compressed package to store all files.

It is recommended that your team clearly define a naming convention for files when working with Godot. One fool-proof convention is to only allow lowercase file and path names.