跳到正文
Skillpedia
通用编程48k · #4766

godot-4-migration

它能做什么

这份指南可以帮你把用 Godot 3 做的游戏更新到 Godot 4。它会讲解代码编写方式的变化(GDScript 2.0)、动画的使用方法(Tween),以及如何声明会出现在游戏设置里的变量(导出变量)。

适用场景

  • ✓当你要把游戏从 Godot 3 升级到 Godot 4 时。
  • ✓当你的游戏代码在升级后无法正常运行时。
  • ✓当你需要修改动画的实现方式时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/godot-4-migration/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/godot-4-migration/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“在 Godot 4 中,我该如何声明配置变量?”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会把旧的 Godot 3 代码与 Godot 4 的新规则进行对比,并举例说明如何改写游戏中的特定部分,比如动画和变量声明。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Godot 4 Migration Guide

Overview

A critical guide for developers transitioning from Godot 3.x to Godot 4. This skill focuses on the major syntax changes in GDScript 2.0, the new Tween system, and export annotation updates.

When to Use This Skill

  • Use when porting a Godot 3 project to Godot 4.
  • Use when encountering syntax errors after upgrading.
  • Use when replacing deprecated nodes (like Tween node vs create_tween).
  • Use when updating export variables to @export annotations.

Migration procedure

Work in a backed-up branch or copy. Choose an exact Godot 4 version, validate conversion before changing files, and inspect converter gaps, renamed nodes, shaders, physics, plugins and export targets. Test scenes and saved games before replacing the working Godot 3 build. Examples below are fragments in an appropriate Node script; Enemy must be a declared project type.

Official guide: Upgrading to Godot 4.

Key Changes

1. Annotations (@)

Godot 4 uses @ for keywords that modify behavior.

  • export var x -> @export var x
  • onready var y -> @onready var y
  • tool -> @tool (at top of file)

2. Setters and Getters

Properties now define setters/getters inline.

Godot 3:

var health setget set_health, get_health

func set_health(value):
    health = value

Godot 4:

signal health_changed(health: int)

var health: int = 100:
    set(value):
        health = value
        emit_signal("health_changed", health)
    get:
        return health

3. Tween System

The Godot 3 Tween node was removed in Godot 4. Use create_tween() in code.

Godot 3:

$Tween.interpolate_property(...)
$Tween.start()

Godot 4:

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)

4. Signal Connections

String-based connections are discouraged. Use callables.

Godot 3:

connect("pressed", self, "_on_pressed")

Godot 4:

pressed.connect(_on_pressed)

Examples

Example 1: Typed Arrays

GDScript 2.0 supports typed arrays for type checking; measure performance rather than assuming a speedup.

# Godot 3
var enemies = []

# Godot 4
var enemies: Array[Node] = []

func _ready():
    for child in get_children():
        if child is Enemy:
            enemies.append(child)

Example 2: Awaiting Signals (Coroutines)

yield is replaced by await.

Godot 3:

yield(get_tree().create_timer(1.0), "timeout")

Godot 4:

await get_tree().create_timer(1.0).timeout

Best Practices

  • ✅ Do: Use @export_range, @export_file, etc., for better inspector UI.
  • ✅ Do: Type all variables (var x: int) for performance gains in GDScript 2.0.
  • ✅ Do: Use super() to call parent methods instead of .function_name().
  • ❌ Don't: Use string names for signals (emit_signal("name")) if you can use the signal object (name.emit()).

Troubleshooting

Problem: "Identifier 'Tween' is not a valid type." Solution: Godot 4 uses a Tween object returned by create_tween(), not a scene node or a SceneTreeTween type. Use var tween: Tween = create_tween() in a Node context.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题

什么是“导出变量”(exports)?

这些变量可以直接在 Godot 的编辑器中进行配置,无需修改代码。在 Godot 4 中,它们使用 `@export` 来声明。

动画(Tween)有哪些变化?

在 Godot 3 中,你需要使用一个名为 Tween 的节点。在 Godot 4 中,则直接在代码里用 `create_tween()` 来创建动画。

为什么我的 `yield` 代码不能用了?

在 Godot 4 中,`yield` 已被 `await` 取代。你只需要在代码中把这个词替换掉即可。

详情

作者的原始描述

Specialized guide for migrating Godot 3.x projects to Godot 4 (GDScript 2.0), covering syntax changes, Tweens, and exports.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4766
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能