计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
godot-compatibility-checker【效率与协作】自动检测和修复Godot 3.x与4.x之间的API兼容性问题,基于实际项目经验提供针对性解决方案
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
当用户遇到Godot版本相关问题或需要进行版本升级时,自动进行兼容性检查和修复:
问题: Invalid assignment of property or key 'emission_amount' on a base object of type 'ParticleProcessMaterial'
修复方案:
# ❌ Godot 3.x 错误写法
var material = ParticleProcessMaterial.new()
material.emission_amount = 50
material.lifetime = 1.5
# ✅ Godot 4.x 正确写法
var particles = GPUParticles2D.new()
var material = ParticleProcessMaterial.new()
particles.amount = 50 # 属性设置在节点层级
particles.lifetime = 1.5 # 属性设置在节点层级
particles.material = material
问题: interpolate_property() 和 set_looped() 方法不存在
修复方案:
# ❌ Godot 3.x 过时写法
var tween = Tween.new()
tween.interpolate_property(object, "property", start, end, 1.0)
tween.set_looped(true)
# ✅ Godot 4.x 现代写法
var tween = create_tween()
tween.tween_property(object, "property", end, 1.0)
# 使用回调实现循环
func animate_loop():
var tween = create_tween()
# 动画代码...
tween.tween_callback(animate_loop)
问题: 信号连接语法变化
修复方案:
# ❌ Godot 3.x 过时写法
connect("input_event", self, "_on_input_event")
# ✅ Godot 4.x 现代写法
input_event.connect(_on_input_event)
# 或使用lambda表达式
signal.signal_name.connect(func(): print("信号触发"))
问题: 鼠标按钮常量名称变化
修复方案:
# ❌ Godot 3.x 过时写法
if event.button_index == BUTTON_LEFT
# ✅ Godot 4.x 现代写法
if event.button_index == MOUSE_BUTTON_LEFT
问题: has_property() 方法被移除
修复方案:
# ❌ Godot 3.x 过时写法
if node.has_property("custom_property"):
value = node.get("custom_property")
# ✅ Godot 4.x 现代写法
if "custom_property" in node:
value = node.get("custom_property")
# 或更安全的检查
var property_value = node.get("custom_property")
if property_value != null:
value = property_value
原始错误: 粒子属性设置位置错误
修复位置: lines 142, 163, 196, 327
修复内容: 将 material.emission_amount 改为 particles.amount
修复内容:
opopped.emit → popped.emit)create_tween() 而非 Tween.new()ParticleProcessMaterial 而非 ParticlesMaterialin 操作符而非 has_property()call_deferred("queue_free")此技能主要使用以下MCP工具:
# 检测Godot版本 (通过Godot MCP)
await godotMCP.detect_godot_version({ projectPath: './project.godot' })
# 检查API兼容性 (通过Godot MCP)
await godotMCP.check_godot_api_compatibility({
code: fileContent,
targetVersion: '4.x'
})
# 自动修复兼容性问题 (通过Godot MCP)
await godotMCP.fix_godot_api_compatibility({
code: problematicCode,
issueIds: detectedIssues
})
detect_godot_version - 检测项目Godot版本check_godot_api_compatibility - 检查代码兼容性fix_godot_api_compatibility - 自动修复兼容性问题get_godot_migration_advice - 获取迁移建议detect_godot_version 确定当前和目标版本check_godot_api_compatibility 全面扫描代码fix_godot_api_compatibility 自动修复问题get_godot_migration_advice 获取最佳实践建议