Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
从 Godot 4.0 升级到 Godot 4.1
对于大多数使用 4.0 制作的游戏和应用程序来说,迁移到 4.1 应该相对安全。本页旨在介绍迁移项目时需要注意的所有事项。
破坏性更改
如果你要从 4.0 迁移到 4.1,这里列出的破坏性更改可能会影响到你。更改按照领域/系统分组。
警告
GDExtension API 在 4.1 中完全不兼容,因此未列入下表。更多信息请参见 将 GDExtension 更新到 4.1 部分。
这篇文章指出了每项破坏性改动是否会影响 GDScript,以及 C# 的破坏性改动是 二进制兼容 还是 源代码兼容:
二进制兼容 —— 现有二进制文件无需重新编译即可加载并成功执行,运行时的行为不会改变。
源代码兼容—— 在升级 Godot 时,源代码可成功编译,无需更改。
核心
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
Basis |
||||
|
✔️ |
✔️ |
✔️ |
|
Object |
||||
|
✔️ |
❌ |
❌ |
|
Transform3D |
||||
|
✔️ |
✔️ |
✔️ |
|
UndoRedo |
||||
|
✔️ |
✔️ |
✔️ |
|
WorkerThreadPool |
||||
|
✔️ |
❌ |
✔️ |
动画
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
AnimationNode |
||||
|
❌ |
❌ |
❌ |
|
|
✔️ |
✔️ |
✔️ |
|
|
✔️ |
✔️ |
✔️ |
|
AnimationNodeStateMachinePlayback |
||||
|
✔️ |
❌ |
❌ |
2D 节点
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
PathFollow2D |
||||
移除了 |
❌ |
❌ |
❌ |
3D 节点
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
Geometry3D |
||||
方法 |
✔️ |
✔️ |
❌ |
|
MeshInstance3D |
||||
方法 |
✔️ |
✔️ |
✔️ |
|
Node3D |
||||
方法 |
✔️ |
✔️ |
✔️ |
|
方法 |
✔️ |
✔️ |
✔️ |
GUI 节点
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
CodeEdit |
||||
方法 |
✔️ |
✔️ |
✔️ |
|
RichTextLabel |
||||
方法 |
✔️ |
✔️ |
✔️ |
|
方法 |
✔️ |
✔️ |
✔️ |
|
方法 |
✔️ |
✔️ |
✔️ |
|
Tree |
||||
方法 |
✔️ |
✔️ |
✔️ |
物理
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
Area2D |
||||
属性 |
❌ |
❌ |
❌ |
|
Area3D |
||||
属性 |
❌ |
❌ |
❌ |
|
PhysicsDirectSpaceState2D |
||||
方法 |
❌ |
❌ |
❌ |
|
PhysicsDirectSpaceState3D |
||||
方法 |
❌ |
❌ |
❌ |
渲染
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
RDShaderFile |
||||
方法 |
✔️ |
❌ |
❌ |
|
RenderingDevice |
||||
方法 |
✔️ |
✔️ |
❌ |
|
RenderingServer |
||||
方法 |
✔️ |
❌ |
❌ |
|
SurfaceTool |
||||
方法 |
✔️ |
✔️ |
❌ |
网络
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
WebRTCPeerConnectionExtension |
||||
方法 |
✔️ |
❌ |
✔️ |
编辑器插件
更改 |
GDScript 兼容 |
C# 二进制兼容 |
C# 源代码兼容 |
引入 |
---|---|---|---|---|
AnimationTrackEditPlugin |
||||
|
❌ |
❌ |
❌ |
|
EditorInterface |
||||
|
✔️ |
❌ |
❌ |
|
方法 |
✔️ |
❌ |
❌ |
|
方法 |
✔️ |
❌ |
❌ |
|
EditorResourcePreviewGenerator |
||||
|
❌ |
❌ |
❌ |
|
|
❌ |
❌ |
❌ |
|
EditorUndoRedoManager |
||||
|
✔️ |
✔️ |
✔️ |
行为更改
4.1 中引入了一些行为的更改,你可能需要调整项目。
更改 |
引入 |
---|---|
SubViewportContainer |
|
当输入事件应传播到 SubViewport 及其子节点时, |
|
如果多层 |
|
Viewport |
|
启用 Physics Picking 的 |
将 GDExtension 更新到 4.1
为了修复一个严重的错误,在 Godot 4.1 中,我们不得不在很大程度上打破二进制兼容性,在很小程度上打破源代码兼容性。
这意味着为 Godot 4.0 制作的 GDExtensions 将需要为 Godot 4.1 重新编译(使用 godot-cpp 的 4.1
分支),并对其源代码稍作修改。
在 Godot 4.0 中,你的“entry_symbol”函数应该是这样:
GDExtensionBool GDE_EXPORT example_library_init(const GDExtensionInterface *p_interface, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_interface, p_library, r_initialization);
init_obj.register_initializer(initialize_example_module);
init_obj.register_terminator(uninitialize_example_module);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init();
}
不过,对于 Godot 4.1 来说,它应该是这样的:
GDExtensionBool GDE_EXPORT example_library_init(GDExtensionInterfaceGetProcAddress p_get_proc_address, const GDExtensionClassLibraryPtr p_library, GDExtensionInitialization *r_initialization) {
godot::GDExtensionBinding::InitObject init_obj(p_get_proc_address, p_library, r_initialization);
init_obj.register_initializer(initialize_example_module);
init_obj.register_terminator(uninitialize_example_module);
init_obj.set_minimum_library_initialization_level(MODULE_INITIALIZATION_LEVEL_SCENE);
return init_obj.init();
}
有 2 个小改动:
第一个参数从
const GDExtensionInterface *p_interface
改为GDExtensionInterfaceGetProcAddress p_get_proc_address
init_obj 变量的构造函数现在会接收
p_get_proc_address
作为第一个参数
You also need to add an extra compatibility_minimum
line to your .gdextension
file, so that it looks something like:
[configuration]
entry_symbol = "example_library_init"
compatibility_minimum = 4.1
这会让 Godot 知道你的 GDExtension 已经更新,可以在 Godot 4.1 中安全加载。