← all posts site ↗

unity scene exporter for AI debugging

writing editor scripts in Unity C# is painful when you're debugging live issues. you want to ask an LLM "why is this GameObject positioned wrong" but the AI has zero context about your scene hierarchy, component state, or asset references.

solved it with a dual-layer approach: a Unity C# editor script that dumps scene state to JSON on trigger, and a companion Python script that reads the JSON and formats it into a prompt-friendly text blob.

the Unity side creates a SceneStateExporter.cs script that traverses all active GameObjects (root + children, including inactive), serializes position/rotation/scale/layer/tag/enabled state, dumps public field values for each component, includes scene name and physics config, and writes JSON to Application.temporaryCachePath.

the Python side triggers the Unity script (via RPC call or manual button), reads the exported JSON, formats it as a condensed text summary (like "MainCamera: pos=(0,1,−10), rot=(0,0,0), component=Camera, FOV=60"), and appends it to the LLM prompt as debugging context.

three pitfalls. asset references: JSON can't serialize Unity object references (materials, textures, prefabs). workaround is dumping names and guids, then resolving on the Python side via the Unity Editor API if needed. large scenes: 100+ GameObjects can produce 50MB+ JSON. added filtering by tag/layer and configurable depth limit. sync timing: the Python script must wait for Unity to finish writing the file. used a simple file-wait loop with 2s timeout instead of fragile polling.

this lets me paste a scene snapshot into a chat and ask "why is the player collider clipping through this wall" with full context. way faster than screenshots and verbal descriptions.