godot-4-migration
将 Godot 3 迁移到 Godot 4
升级 Godot 项目的游戏开发者会遇到语法错误和已弃用的功能。本技能提供了一份全面的指南,包含具体示例,帮助迁移 GDScript 2.0 代码。
下载技能 ZIP
在 Claude 中上传
前往 设置 → 功能 → 技能 → 上传技能
开启并开始使用
测试它
正在使用“godot-4-migration”。 将此 Godot 3 代码转换为 Godot 4:export var speed = 10
预期结果:
在 Godot 4 中,使用 @export 注解:
```gdscript
@export var speed: int = 10
```
你还可以添加类型提示和检查器提示:
```gdscript
@export_range(1, 100) var speed: int = 10
```
正在使用“godot-4-migration”。 如何在 Godot 4 中使用 Tweens?
预期结果:
Tween 节点已弃用。使用 create_tween() 方法:
```gdscript
var tween = create_tween()
tween.tween_property($Sprite, 'position', Vector2(100, 100), 1.0)
tween.parallel().tween_property($Sprite, 'modulate:a', 0.0, 1.0)
```
安全审计
安全All static findings are false positives. The skill contains only documentation for Godot 4 migration with GDScript code examples. No shell commands, cryptographic code, or system reconnaissance present.
中风险问题 (3)
质量评分
你能构建什么
移植游戏项目
通过逐步语法指导,系统地将整个游戏项目从 Godot 3.x 升级到 Godot 4。
修复语法错误
在 Godot 4 中打开 Godot 3 项目时,快速解决编译错误。
学习 GDScript 2.0
了解 GDScript 2.0 中的新功能和模式,用于新的 Godot 4 开发。
试试这些提示
如何在 Godot 4 中转换 @export var?展示旧语法和新语法。
将此 Godot 3 Tween 代码转换为 Godot 4:$Tween.interpolate_property($Sprite, 'position', Vector2(0,0), Vector2(100,100), 1.0, 0, 0)
在 Godot 4 中如何使用 callables 连接信号,而不是使用 connect('signal_name', self, '_handler')?列出将 Godot 3 项目迁移到 Godot 4 所需的所有主要语法更改,并为每个类别提供示例。
最佳实践
- 使用 @export_range、@export_file 和其他 @export 注解以获得更好的编辑器集成
- 为 GDScript 2.0 中的性能提升,使用显式类型提示对所有变量进行类型标注
- 使用 super() 调用父类方法,而不是旧的 .method_name() 语法
避免
- 当可以使用信号对象的 name.emit() 时,不要使用 emit_signal('name')
- 不要使用基于字符串的信号连接,如 connect('pressed', self, '_handler')
- 不要在 Godot 4 中使用 yield() 进行协程 - 改用 await