一键导入
godot-clean-conflicts
当 Godot 代码中存在相互冲突的操作导致未定义行为时使用。检测同一属性在多处设置 (_ready、_process、代码+编辑器)、同一 Signal 多次连接、冲突的物理模式、 竞争的动画等问题。自动通过明确的所有权归属解决冲突。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
当 Godot 代码中存在相互冲突的操作导致未定义行为时使用。检测同一属性在多处设置 (_ready、_process、代码+编辑器)、同一 Signal 多次连接、冲突的物理模式、 竞争的动画等问题。自动通过明确的所有权归属解决冲突。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
当 Godot 代码中存在通过 get_node()、get_parent() 或直接引用产生的紧耦合依赖时使用。 检测耦合模式并将其转换为基于 Signal 的通信方式。组件变得独立、可测试且可复用。 在改进架构的同时精确保留原有行为。
用于创建带有自定义面板、停靠栏和工具的 Godot 编辑器插件。生成 plugin.cfg 配置、 EditorPlugin 脚本模板、自定义编辑器 UI 组件,并集成 ProjectSettings。按照 Godot 4.x 最佳实践创建完整的插件结构。
当 Godot 代码中存在硬编码的游戏数据(如 const 数组、字典或内嵌值)时使用。检测内联数据 如敌人属性、物品定义、关卡配置等。自动提取为 .tres Resource 文件,使数据在编辑器中 可见、易于修改,并支持数据驱动的设计。
当构建 Godot 功能时,代码使用 .new() 创建节点而非使用场景时触发。 检测 Timer.new()、Area2D.new()、Sprite2D.new() 等代码创建的对象。 自动生成 .tscn 场景文件,更新父脚本使用 @onready 引用,并创建可复用的组件库。
当 Godot 项目在编辑器(.tscn)和代码(.gd)之间存在位置冲突、相机跟随背景、 或运行时位置与编辑器预览不匹配时使用。编排所有 3 个位置同步子技能: sync-static-positions、sync-camera-positions 和 sync-parallax。 每个操作针对特定的位置冲突类型。
在开发 Godot 游戏时需要为 GDScript 类、Signal、场景初始化和集成流程提供全面的测试覆盖时使用。 生成 GUT 框架单元测试、集成测试、Mock/Stub 辅助工具和 CI/CD 测试运行器配置。
| name | godot-clean-conflicts |
| version | 3.0.0 |
| displayName | 清理冲突操作 |
| description | 当 Godot 代码中存在相互冲突的操作导致未定义行为时使用。检测同一属性在多处设置 (_ready、_process、代码+编辑器)、同一 Signal 多次连接、冲突的物理模式、 竞争的动画等问题。自动通过明确的所有权归属解决冲突。 |
| author | Asreonn |
| license | MIT |
| category | game-development |
| type | tool |
| difficulty | intermediate |
| audience | ["developers"] |
| keywords | ["godot","conflicts","race-conditions","duplicate-signals","physics-modes","animation-conflicts","gdscript","undefined-behavior"] |
| platforms | ["macos","linux","windows"] |
| repository | https://github.com/asreonn/godot-superpowers |
| homepage | https://github.com/asreonn/godot-superpowers#readme |
| permissions | {"filesystem":{"read":[".gd",".tscn",".tres"],"write":[".gd",".tscn"]},"git":true} |
| behavior | {"auto_rollback":true,"validation":true,"git_commits":true} |
| outputs | 冲突解决方案、明确的所有权模式、更新后的代码/场景、git 提交 |
| requirements | Git 仓库, Godot 4.x |
| execution | 自动检测,用户审批解决策略 |
| integration | godot-refactor 编排器的一部分,解决架构冲突 |
每个属性只有一个真实来源。 冲突操作会导致未定义行为和调试噩梦。
查找如下模式:
# player.gd
func _ready():
position = Vector2(100, 100) # Code sets position
# BUT: .tscn also has position = Vector2(200, 200)
# CONFLICT: Which position wins?
func _process(delta):
rotation += delta # Animation system ALSO modifying rotation
# CONFLICT: Animation vs code control
解决为明确的所有权归属:
# player.gd
# Position is set in .tscn (editor owns position)
# Rotation is controlled by animation (animation owns rotation)
func _process(delta):
# Rotation conflict removed
pass
识别以下问题:
属性值不正确,且不知道原因。
时好时坏(依赖时序)。
Signal 触发两次,操作执行多次。
代码试图直接控制物理体。
转换前(冲突):
# enemy.gd
func _ready():
position = Vector2(500, 300) # Code says here
# enemy.tscn
[node name="Enemy" type="CharacterBody2D"]
position = Vector2(100, 100) # Editor says here
# RESULT: Confusing! Editor shows one place, game uses another
转换后(解决 - 编辑器优先):
# enemy.gd
func _ready():
# Position is set in scene file for editor visibility
pass
# enemy.tscn
[node name="Enemy" type="CharacterBody2D"]
position = Vector2(500, 300) # Updated to match intended position
# RESULT: What You See Is What You Get
转换前(冲突):
# ui.gd
func _ready():
button.pressed.connect(_on_button_pressed)
func setup_ui():
button.pressed.connect(_on_button_pressed) # CONNECTED AGAIN!
# RESULT: _on_button_pressed fires TWICE per click
转换后(解决):
# ui.gd
func _ready():
if not button.pressed.is_connected(_on_button_pressed):
button.pressed.connect(_on_button_pressed)
func setup_ui():
# Connection already exists, skip
pass
# RESULT: Fires exactly once per click
转换前(冲突):
# player.gd
func _process(delta):
sprite.rotation += delta * rotation_speed # Code controls rotation
# player.tscn has AnimationPlayer controlling sprite.rotation
# RESULT: Jittery rotation, both systems fighting
转换后(解决 - 动画优先):
# player.gd
func _process(delta):
# Rotation is controlled by animation system
# Code can trigger animations: animation_player.play("rotate")
pass
# AnimationPlayer has full control of sprite.rotation
# RESULT: Smooth animation, clear ownership
转换前(冲突):
# enemy.gd
extends RigidBody2D
func _physics_process(delta):
position = target_position # CONFLICT with physics engine!
# Physics engine wants to control position
# Code also tries to control position
# RESULT: Jittery movement, physics fighting code
转换后(解决 - 使用正确的 Body 类型):
# enemy.gd
extends CharacterBody2D # Changed to CharacterBody for code control
func _physics_process(delta):
position = target_position # Now appropriate for CharacterBody
# CharacterBody2D is designed for code-controlled movement
# RESULT: Smooth movement, no conflict
备选解决方案(保留 RigidBody):
# enemy.gd
extends RigidBody2D
func _physics_process(delta):
# Use forces instead of direct position control
apply_force((target_position - position) * force_strength)
# Work WITH physics engine, not against it
# RESULT: Realistic physics-based movement
将代码中定义的值移到 .tscn 中,以便在编辑器中可见。
当代码需要完全控制时,移除编辑器中的值。
代码触发动画,不直接修改属性。
使用力/脉冲而非直接控制属性。
建立清晰的模式:编辑器负责初始值,代码负责后续变更。
检测冲突严重程度:
按优先级解决:
可与以下技能配合使用:
以下情况不需要"修复":
并非所有冲突都是 bug — 有些是架构模式。
| 冲突类型 | 症状 | 解决方案 |
|---|---|---|
| _ready 和 .tscn 中同时设置位置 | 游戏中位置不正确 | 编辑器优先(移到 .tscn) |
| 重复的 Signal 连接 | 事件触发多次 | 先检查 is_connected() |
| 动画 + 代码控制旋转 | 动画抖动 | 动画优先(移除代码) |
| RigidBody 位置控制 | 物理异常 | 改用力 |
| _process + _physics_process | 行为不一致 | 根据需要选择其一 |
对于每个解决方案,添加如下注释:
# Position is controlled by .tscn (editor-visible)
# Rotation is controlled by AnimationPlayer "idle"
# Scale is controlled by code (dynamic resizing)
明确的所有权 = 清晰的代码。