应用简介
Godot 3.x项目迁移至Godot 4(GDScript 2.0)的专业指南,涵盖语法变化、补间动画和导出。
---
name: godot-4-migration
description: "Specialized guide for migrating Godot 3.x projects to Godot 4 (GDScript 2.0), covering syntax changes, Tweens, and exports."
risk: safe
source: community
date_added: "2026-02-27"
---
# 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.
## 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:**
```gdscript
var health setget set_health, get_health
func set_health(value):
health = value
```
**Godot 4:**
```gdscript
var health: int:
set(value):
health = value
emit_signal("health_changed", health)
get:
return health
```
### 3. Tween System
The `Tween` node is deprecated. Use `create_tween()` in code.
**Godot 3:**
```gdscript
$Tween.interpolate_property(...)
$Tween.start()
```
**Godot 4:**
```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)
```
### 4. Signal Connections
String-based connections are discouraged. Use callables.
**Godot 3:**
```gdscript
connect("pressed", self, "_on_pressed")
```
**Godot 4:**
```gdscript
pressed.connect(_on_pressed)
```
## Examples
### Example 1: Typed Arrays
GDScript 2.0 supports typed arrays for better performance and type safety.
```gdscript
# 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:**
```gdscript
yield(get_tree().create_timer(1.0), "timeout")
```
**Godot 4:**
```gdscript
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:** `Tween` is now `SceneTreeTween` or just an object returned by `create_tween()`. You rarely type it explicitly, just use `var tween = create_tween()`.
## 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.
发布日期
5/16/2026
提供方
SkillOPIC
来源类型
导入
sickn33
coding
数据安全
使用 Skill 时,您的对话内容将被发送至 AI 模型进行处理。我们会严格保护您的隐私数据,不会将您的对话内容用于模型训练或分享给第三方。 以下为此 Skill 的数据处理说明。
此 Skill 将处理您的对话输入
您的消息将作为 Prompt 上下文发送至 AI 模型
所有通信均通过加密通道传输
对话记录仅保存在本地
您可以随时清除本地对话历史,清除后数据不可恢复
评分和评价
已验证评分
Skill 信息
了解此 Skill 的详细信息和功能特性
编程开发
前端开发
文件结构
SKILL.md3.3 KB
版本历史
- 公开
- 来源于用户导入
如需详细了解相关要求,请访问帮助中心,或给我们提交反馈信息