Chemins d'accès aux fichiers dans les projets Godot¶
Cette page explique comment les chemins de fichiers fonctionnent dans les projets Godot. Vous apprendrez comment accéder aux chemins dans vos projets en utilisant les notations res://
et user://
, et où Godot stocke les fichiers utilisateurs sur votre disque-dur.
Séparateurs de chemin¶
To make supporting multiple platforms easier, Godot uses UNIX-style path
separators (forward slash /
). These work on all platforms, including
Windows.
Instead of writing paths like C:\Projects\Game
, in Godot, you should write
C:/Projects/Game
.
Windows-style path separators (backward slash \
) are also supported in some
path-related methods, but they need to be doubled (\\
), as \
is normally
used as an escape for characters with a special meaning.
This makes it possible to work with paths returned by other Windows applications. We still recommend using only forward slashes in your own code to guarantee that everything will work as intended.
Accessing files in the project folder (res://
)¶
Godot considère qu'un projet existe dans tout dossier qui contient un fichier texte project.godot
, même si ce fichier est vide. Le dossier qui contient ce fichier est le dossier racine de votre projet.
Vous pouvez accéder à n'importe quel fichier de manière relative à celui-ci en écrivant des chemins commençant par res://
, qui représente les ressources. Par exemple, vous pouvez accéder à un fichier d'image character.png
situé dans le dossier racine du projet dans le code avec le chemin suivant : res://some_texture.png
.
Accessing persistent user data (user://
)¶
Pour stocker des fichiers de données persistants, comme la sauvegarde ou les paramètres du joueur, vous devez utiliser user://
au lieu de res://
comme préfixe de votre chemin. En effet, lorsque le jeu est en cours d'exécution, le système de fichiers du projet sera probablement en lecture seule.
The user://
prefix points to a different directory on the user's device.
Unlike res://
, the directory pointed at by user://
is created
automatically and guaranteed to be writable to, even in an exported project.
The location of the user://
folder depends on what is configured in the
Project Settings:
By default, the
user://
folder is created within Godot's editor data path in theapp_userdata/[project_name]
folder. This is the default so that prototypes and test projects stay self-contained within Godot's data folder.If application/config/use_custom_user_dir is enabled in the Project Settings, the
user://
folder is created next to Godot's editor data path, i.e. in the standard location for applications data.By default, the folder name will be inferred from the project name, but it can be further customized with application/config/custom_user_dir_name. This path can contain path separators, so you can use it e.g. to group projects of a given studio with a
Studio Name/Game Name
structure.
Sur les plateformes de bureau, les emplacements des dossiers pour user://
sont actuellement :
Type |
Localisation |
---|---|
Default |
Windows :
%APPDATA%\Godot\app_userdata\[project_name] macOS :
~/Library/Application Support/Godot/app_userdata/[nom_du_projet] Linux :
~/.local/share/godot/app_userdata/[nom_du_projet] |
Custom dir |
Windows :
%APPDATA%\[project_name] macOS :
~/Library/Application Support/[project_name] Linux :
~/.local/share/[project_name] |
Custom dir and name |
Windows:
%APPDATA%\[custom_user_dir_name] macOS:
~/Library/Application Support/[custom_user_dir_name] Linux:
~/.local/share/[custom_user_dir_name] |
[project_name]
est basé sur le nom de l'application défini dans les Paramètres du projet, mais vous pouvez le modifier en fonction de la plateforme en utilisant feature tags.
Sur plateformes mobiles, ce chemin est unique au projet et n'est pas accessible aux autres applications pour des raisons de sécurité.
Sur les exportations HTML5, user://
fera référence à un système de fichiers virtuel stocké sur le périphérique via IndexedDB. (L'interaction avec le système de fichiers principal peut toujours être effectuée par le singleton JavaScript.)
Converting paths to absolute paths or "local" paths¶
You can use ProjectSettings.globalize_path()
to convert a "local" path like res://path/to/file.txt
to an absolute OS path.
For example, ProjectSettings.globalize_path()
can be used to open "local" paths in the OS file manager
using OS.shell_open() since it only accepts
native OS paths.
To convert an absolute OS path to a "local" path starting with res://
or user://
, use ProjectSettings.localize_path().
This only works for absolute paths that point to files or folders in your
project's root or user://
folders.
Chemins de données de l'éditeur¶
The editor uses different paths for editor data, editor settings, and cache, depending on the platform. By default, these paths are:
Type |
Localisation |
---|---|
Editor data |
Windows :
C:\Users\[username]\AppData\Roaming\Godot\app_userdata\[Name] macOS :
~/Library/Application Support/Godot/ Linux:
~/.local/share/godot/ |
Editor settings |
Windows :
C:\Users\[username]\AppData\Roaming\Godot\app_userdata\[Name] macOS :
~/Library/Application Support/Godot/ Linux :
~/.config/godot/ |
Cache |
Windows :
%TEMP%\Godot\ macOS :
~/Library/Caches/Godot/ Linux :
~/.cache/godot/ |
Editor data contains export templates and project-specific data.
Editor settings contains the main editor settings configuration file as well as various other user-specific customizations (editor layouts, feature profiles, script templates, etc.).
Cache contains data generated by the editor, or stored temporarily. It can safely be removed when Godot is closed.
Godot est conforme à la XDG Base Directory Specification sur toutes les plateformes. Les variables d'environnement peuvent être remplacées selon la spécification pour modifier les chemins de données de l'éditeur et du projet.
Note
Si vous utilisez Godot comme package Flatpak, les chemins de données de l'éditeur seront situés dans des sous-dossiers de ~/.var/app/org.godotengine.Godot/
.
Mode autonome¶
If you create a file called ._sc_
or _sc_
in the same directory as the
editor binary (or in MacOS/Contents/ for a macOS editor .app bundle), Godot
will enable self-contained mode.
This mode makes Godot write all editor data, settings, and cache to a directory
named editor_data/
in the same directory as the editor binary.
You can use it to create a portable installation of the editor.
La version Steam de Godot utilise le mode autonome par défaut.
Note
Le mode autonome n'est pas encore supporté pour les projets exportés. Pour lire et écrire des fichiers dans un chemin relatif à l’exécutable, utilisez OS.get_executable_path(). Notez que l’écriture de fichiers dans le chemin de l’exécutable ne fonctionne que s'il est placé dans un emplacement qui autorise l’écriture (ex. Pas dans Programmes ou tout autre dossier en lecture seule pour les utilisateurs de base).