Safety & Git Hygiene
Never let an agent eat your scene
Verified against a working setup on 2026-08-10
An agent editing your Unity project is doing something a normal AI chat cannot: making changes you did not see happen. That is the entire value, and the entire risk. This chapter is the boring part that saves your weekend.
The one rule
git restore away. If it is not, you are hand-reconstructing a scene file.# Before every session
git status # must be clean
git switch -c ai/stamina-system
# After, review honestly
git diff --stat
git diff -- "*.cs" # read every line of script changes
# If it went wrong
git restore .
git clean -fd # removes files it createdWhy Unity makes this harder
Reviewing a code diff is easy. Reviewing a Unity diff is not, and it is worth understanding why before you trust an agent with scene edits.
- Scenes and prefabs are YAML full of GUIDs. A one-object change can produce hundreds of diff lines that mean nothing to a human reader.
- Reordering is invisible in intent. Unity may rewrite unrelated parts of a scene file just from being opened and saved.
- .meta files matter. Delete or regenerate one and every reference to that asset breaks — often silently, showing up later as a missing script.
- The Editor holds state in memory. An agent writing files while Unity has unsaved changes can have its work overwritten, or overwrite yours.
Set up git properly for Unity
If you have not already, two settings make Unity diffs dramatically more reviewable. Both are in Edit → Project Settings → Editor.
| Setting | Set to | Why |
|---|---|---|
Version Control Mode | Visible Meta Files | Meta files are tracked in git, so references survive. |
Asset Serialization | Force Text | Scenes become readable YAML instead of binary. |
Tool permissions
Read tools and write tools deserve very different levels of trust. This split holds regardless of which client you use.
| Tools | Risk | Recommendation |
|---|---|---|
Read console, read scene, search | None | Always allow. Most of the value lives here. |
Profiler, capture screenshots | None | Always allow. |
Create or edit scripts | Low | Fine on a clean branch. Read the diff. |
Modify GameObjects or scenes | High | Ask every time. Hard to review afterwards. |
Delete assets or scripts | High | Ask every time. Meta files break references. |
Run arbitrary menu items | Highest | A menu item can do anything, including build or wipe. |
Scope your prompts
Most damage comes from an unbounded instruction rather than a malicious one. The model does exactly what you asked across a wider surface than you pictured.
In Assets/Scripts/Enemies only, rename the field
"hp" to "currentHealth" and update every reference
within that folder. List each file you changed.Rename hp to currentHealth everywhere.
// "Everywhere" includes third-party assets in
// Assets/Plugins, which now no longer compile,
// and which you did not write and cannot easily fix.Things to never let it touch
- Library/ — Unity's generated cache. Editing it corrupts the project. It should be gitignored anyway.
- ProjectSettings/ — changes here affect physics, layers, and build config globally, and are easy to miss in review.
- Packages/manifest.json — unless you are deliberately adding a package. A bad edit breaks the whole project on next import.
- Third-party asset folders — you cannot meaningfully review changes to code you did not write.
Recovering
When something has clearly gone wrong
Stop the agent first. Letting it continue while you investigate compounds the problem.
# 1. See the scale of it
git status
git diff --stat
# 2. Nuclear option - back to last commit
git restore .
git clean -fd
# 3. Or keep the good parts
git restore --source=HEAD -- Assets/Scenes/
git diff -- Assets/Scripts/ # review, keep what is rightThen close and reopen Unity. The Editor caches asset state in memory, so after a git restore it can still be showing you the reverted-away version until it reimports.
If you were not on a branch and had not committed
Check your editor's local history first — VS Code, Rider and Visual Studio all keep per-file timelines that survive external changes, and they are often enough to recover a script.
Scenes are harder. Unity keeps no equivalent history. This is precisely why the commit-first rule is the first thing in this chapter rather than the last.
What to take away
- Commit before every agent session, and work on a branch.
- Turn on Force Text and Visible Meta Files before anything else.
- Always allow read tools; keep scene, delete and menu tools on ask.
- Scope every prompt to a folder or the open scene.
- Keep it out of Library, ProjectSettings, and third-party folders.
- Reopen Unity after a git restore so it reimports.