---
name: ferret-level-editor
description: Use when an agent builds or changes a Ferret level by commands: edit.open, edit.entity/spawn/zone/anim/physics.*, edit.material.* (look of a model or one object, live), edit.patch, undo/redo, edit.validate, edit.diff, edit.save, with the model viewer for screenshots.
---

# Editing a level by commands

## When to use
Putting entities in a level, adding zones, spawns, animation graphs, physics settings, or fixing a manifest without hand-editing JSON.

## The model
`@ferret/editor` edits a **draft** of a level's manifest through commands on `world.commands`. Every edit is a JSON-pointer patch (`add`, `replace`, `remove`) with its undo; a person in the editor and an agent share one undo history. Nothing is written until `edit.save`, which is refused while the draft is invalid.

## Steps
1. `edit.open {level}` (draft; `live` reloads the level after each edit).
2. Read with `edit.get {path?}` (a JSON pointer such as `/entities/0/params`).
3. Change with the typed commands: `edit.entity.add|set|remove|duplicate`, `edit.spawn.*`, `edit.zone.*`, `edit.collider.set`, `edit.navmesh.rebuild`, `edit.anim.*`, `edit.physics.*` (material, constraint, fracture, set), `edit.material.*` (below). Use `edit.patch {ops}` only when no typed command fits.
4. `edit.validate`, then `edit.diff` to see exactly what changed.
5. Look: the model viewer (`pnpm viewer`, `pnpm viewer:headless`) relays commands and serves screenshots of the active camera.
6. `edit.save`. `edit.undo` / `edit.redo` / `edit.history` while working.

## Materials, live
The look of a glTF material is changed on the running level with **no reload** (the next frame shows it; `edit.undo`/`edit.redo`, `edit.diff`, `edit.save` into the manifest's `materialLooks`). Never by the bare material name (it stands in twenty places): two scopes, then the glTF material name inside the model. **type** (default): a model's uid, all its instances. **instance**: one object's uid, wins over the type.
- `edit.material.list {scope?, filter?, limit?}`: addresses `{uid, via, meshes, materials, ambiguous?, look}`; `unresolved` = draft uids nothing answers to.
- `edit.material.get {scope?, uid, material?}`: the draft's looks and what the scene shows now.
- `edit.material.set {scope?, uid, material, values}`: merged, `null` removes one value. `values`: `baseColor` [r,g,b(,a)] linear 0..1, `metallic`, `roughness`, `emissive`, `emissiveStrength`, `normalScale`, `alpha` {mode, cutoff}, `doubleSided`, `maps` {baseColor|normal|orm|emissive|opacity}. Refused: an unknown uid, a material the model lacks, an **ambiguous** address (two things answer to it: give the objects a uid in the export).
- `edit.material.remove {scope?, uid, material?}`.
Example: `edit.material.set {scope:"instance", uid:"StaticMeshActor_12", material:"MI_Wood", values:{roughness:0.7}}`, then a screenshot. Where uids come from, and the limits: concepts/levels.md ("Material looks").

## Check afterwards
`edit.validate` is empty; `edit.colliders.missing` lists no large non-solid mesh you meant to be solid; a screenshot shows the level; the level plays.

## What usually goes wrong
- Node names that do not exist in the glTF (the loader cannot wire them: `edit.validate` reports it).
- Removing a state or graph still used.
- Forgetting `edit.navmesh.rebuild` after moving solid meshes.
- Editing with `live` off and not calling `edit.reload`.
- A look addressed by the bare material name (the same name stands in twenty places): always a type uid or an instance uid from `edit.material.list`, and the material name inside it.

## Files

- `reference/levels.md` — The level manifest, the level registry and travel, environment, and the .ferret package format.
- `reference/commands.md` — The debug command channel: how a tool, the inspector or an AI agent drives a running game, and the commands each package registers.
- `reference/api-editor.md` — every export of `@ferret/editor` with signature and doc comment
- `reference/commands.md` — 105 commands of these packages with their arguments
