Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
TSCN 文件格式¶
TSCN(文本场景)文件格式表示 Godot 内部的单个场景树。与二进制的 SCN 文件不同,TSCN 具有易于人类阅读、便于使用版本控制系统进行管理的优点。
The ESCN (exported scene) file format is identical to the TSCN file format, but
is used to indicate to Godot that the file has been exported from another
program and should not be edited by the user from within Godot.
Unlike SCN and TSCN files, during import, ESCN files are compiled to binary
SCN files stored inside the .godot/imported/
folder.
This reduces the data size and speeds up loading, as binary formats are faster
to load compared to text-based formats.
To make files more compact, properties equal to the default value are not stored in scene/resource files. It is possible to write them manually, but they will be discarded when saving the file.
如果想要完整的描述,对这些文件格式的解析是在 resource_format_text.cpp 的 ResourceFormatLoaderText
类中进行处理的。
备注
The scene and resource file formats have changed significantly in Godot 4, with the introduction of string-based UIDs to replace incremental integer IDs.
Mesh, skeleton and animation data is also stored differently compared to Godot 3. You can read about some of the changes in this article: Animation data rework for 4.0
Scenes and resources saved with Godot 4.x contain format=3
in their
header, whereas Godot 3.x uses format=2
instead.
文件结构¶
TSCN 文件分为五个主要部分:
文件描述符
外部资源
内部资源
节点
连接
The file descriptor looks like [gd_scene load_steps=4 format=3 uid="uid://cecaux1sm7mo0"]
and should be the first entry in the file. The load_steps
parameter is equal to the
total amount of resources (internal and external) plus one (for the file itself).
If the file has no resources, load_steps
is omitted. The engine will
still load the file correctly if load_steps
is incorrect, but this will affect
loading bars and any other piece of code relying on that value.
uid
is an unique string-based identifier representing the scene. This is
used by the engine to track files that are moved around, even while the editor
is closed. Scripts can also load UID-based resources using the uid://
path
prefix to avoid relying on filesystem paths. This makes it possible to move
around a file in the project, but still be able to load it in scripts without
having to modify the script. Godot does not use external files to keep track of
IDs, which means no central metadata storage location is required within the
project. See this pull request
for detailed information.
These sections should appear in order, but it can be hard to distinguish them.
The only difference between them is the first element in the heading for all of
the items in the section. For example, the heading of all external resources
should start with [ext_resource ...]
.
A TSCN file may contain single-line comments starting with a semicolon (;
).
However, comments will be discarded when saving the file using the Godot editor.
Whitespace within a TSCN file is not significant (except within strings), but
extraneous whitespace will be discarded when saving the file.
文件中的条目¶
A heading looks like
[<resource_type> key1=value1