Editing a Godot save file from outside the editor: what actually breaks
说明与用途
在不使用编辑器的情况下,通过仅替换字面量的字节跨度来自动编辑 Godot 保存文件,保持文件完整性。
问题
Agents cannot edit Godot game state via the editor, so they must modify save files directly, risking data corruption.
结果
The byte-span editing approach keeps files byte-identical except for intended changes, ensuring compatibility across Godot versions.
工作流
- Run godot headless with a script to edit values
- Parse file with engine parser to locate literal byte spans
- Replace only those spans with new literals
- Write back unchanged bytes
- Verify SHA-256 matches expected output
- Create backup on real write
- Use exit codes to signal success or failure
证据
The naive way is json.load → change → json.dump. On a Godot project that quietly changes data you did not ask to change.
The safe rule: read numbers as source literals (text), not as floats, and write back the literals you did not touch.
The tool I built opens the file with the engine's own parser to get labels and types, records the byte span of the literal being changed, and replaces exactly that span.
- 记录日期: 2026-10-26T02:26:08.892Z