unity-prefab-edit
Skill1 starsChanged 38 days agoApache-2.0View on GitHub
Changes what a prefab is in the user's Unity project through the Unity connection (Unity's own CLI as an MCP server) - a variant of a pack's piece, a different default scale, a collider or another component with its values, another material, a child renamed or turned off - and swaps the copies already placed in a scene for the changed prefab. Use when the user asks to edit, modify, adjust or make a variant of a prefab, to add a collider, component, script values or material to a prefab, to change a prefab's size or pivot, or to replace the instances of a prefab in a scene with a new or changed one. For placing and arranging prefabs in a scene, see unity-scene-assembly.
In this repository16 other files it gives its agents.
- blender-game-exportSkill
- blender-low-polySkill
- blender-materials-renderSkill
- blender-modelingSkill
- comfyui-image-to-3dSkill
- deep-researchSkill
- githubSkill
- human-writingSkill
- seoSkill
- skill-creatorSkill
- social-instagramSkill
- social-linkedinSkill
- social-tiktokSkill
- social-xSkill
- social-youtubeSkill
- unity-scene-assemblySkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 74
Delete the instance and the _PrefabEdit root (delete_gameobject).
- Very specific: line 104
Capture, look, correct: When copies in a scene changed, one capture framed on them with the review camera from unity-scene-assembly, …
- Distinctive: line 155
Nothing by eye: Every number you set (a scale, a collider size, a position) is computed from values you read.
- Very specific: line 169
Delete them in one round (delete_gameobject each), instantiate the variant once per copy in the next (instantiate_prefab with the same name …
- Very specific: line 174
Verify two or three at random by reading their Transform back, and say which.
- Very specific: line 184
Project settings, packages, import settings of models: Not part of editing a prefab.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Editing prefabs in Unity
A prefab is a reusable thing: every copy of it in every scene follows the asset. This
skill is for changing the thing itself (its size, its components, its material, its
children) and for bringing the copies in a scene up to date. Arranging copies in a scene
(where they go, how many, how they face) is unity-scene-assembly's work: open that one
when the request is about placement; open both when it is about both.
Everything here goes through the typed tools of the Unity connection. You never write
or run code for this work: not eval, eval_file, run_script, write_text_file,
create_script or menu. Every one of them waits for the user's approval, and nothing
in editing a prefab needs them: the typed tools read and set every serialized value,
fit a collider to a mesh, and apply the result to the asset.
Your Unity connection
The connection is Unity's own MCP server; its tools are unity_…. The editor must be
open on the project: if the connection shows no tools, say so and stop (the user opens
the project, or presses Reconnect in Tools → Connections). Do not describe work as done
when you could not do it.
- Find the asset:
find_assetswithtype: "GameObject", anamesubstring,search_inthe pack's or the project's folder, a smalllimit. It returns paths and GUIDs; a path is the handle every other tool takes. - Find copies in the scene:
find_gameobjectsbynameorhierarchy_path,searchwithh: <name>(a Unity Search query, with alimit),get_selection. - Read:
get_component_properties(targetthe GameObject plustype, or a component handle) gives a component's serialized values;get_serialized_fieldsgives the same with each field's path and type, which is what you need before setting something whose name you are not sure of;get_material_propertiesreads a material's shader and properties. - Change an instance:
set_transform(position,rotationin degrees,scale; omitted channels stay),add_component(target,typesuch asBoxCollider),remove_component,set_component_properties(properties: a map of serialized property name to value; vectors and colors as arrays, object references as handles),set_active,rename_gameobject,set_parent. - Prefab assets:
create_prefab_variant(basepath, variantpath),create_prefab(a scene object saved as a new asset),instantiate_prefab(prefabpath, optionalname),apply_prefab_overridesandrevert_prefab_overrides(on aninstance),unpack_prefab,save_prefab_contents(only two edits:rename_childwithnew_name, andset_active_childwithactive; it cannot change a transform, a component or a material). - Other assets:
copy_asset(asset,destinationpath),rename_asset,move_asset,set_material_properties(material,propertieswith the leading underscore such as_BaseColor),delete_asset(destructive; only when asked). - Scenes and captures:
list_open_scenes,save_scene,save_all, and the review camera described inunity-scene-assembly("Showing the result").
The one rule: a prefab is edited through an instance
The tools that change transforms, components and materials work on GameObjects in a
scene, and save_prefab_contents only renames or toggles children. So a change to the
asset is always this loop:
instantiate_prefabthe asset (the base, or the variant you just created) into the active scene, under a temporary empty named_PrefabEditthat you create first. Where it lands does not matter; leave its position alone.- Change the instance with the typed tools:
set_transformfor a default scale,add_componentandset_component_propertiesfor components, the material steps below for a material. apply_prefab_overrideson the instance. Every override on it goes into the asset the instance comes from: the variant when you instantiated a variant, the base when you instantiated the base. Read the instance's properties once more right after, as the check that the values you meant are the ones applied.- Delete the instance and the
_PrefabEditroot (delete_gameobject). What stays is the asset.
The same loop, with revert_prefab_overrides instead of apply, is how a copy in the
scene is put back to what its asset says.
Workflow
- Look, narrowly. The asset the user names, by
find_assets; one existing copy of it in the scene if there is one, byfind_gameobjects; itsTransformand the components the request touches, read in a single round ofget_component_propertiescalls (several calls in one round, not one per round). Do not fetch the scene's whole hierarchy to find a prefab's copies:searchwithh: <name>lists them. - Base or variant. A prefab that came with an asset pack is not edited: changing it
changes every copy in every scene, and the pack's next update overwrites it. The
user's change becomes a variant, created with
create_prefab_variantnext to the base (or in the user's own folder,Assets/_Project/…, when the pack's folder is read-only to them), named as the user said or, if they did not, as the base plus a suffix that says what changed (_Tall,_NoCollider). The base itself is edited only when the user names it and asks for the base to change; then say in the report that every copy in the project changed with it. A prefab the user made (in their own folder) is theirs to edit directly when they ask. - Plan in parts, against the step budget. Say in one line what you will change, on which asset, and what you will not touch.
- Edit through an instance (the loop above). Group the changes: all the
set_transform,add_componentandset_component_propertiescalls on the temporary instance in one round,apply_prefab_overridesin the next. - Replace the copies, when the user asked for the scene to use the changed prefab (a variant does not replace the base's copies by itself). See "Replacing copies in a scene".
- Capture, look, correct. When copies in a scene changed, one capture framed on
them with the review camera from
unity-scene-assembly, re-aimed before the capture. A change to the asset alone has no picture: its proof is the values you read back. - Save and report.
save_scenewhen the scene changed and the user wants it to stay (a variant or an applied override is already on disk: assets save themselves); the report is in "Before you say it is done".
Your step budget
- Open this skill once; do not reopen it in the same conversation.
- About 2 rounds to look, 1 for the variant, 2 for the edit loop, 3-4 to replace the copies, 1 capture, 1 spare. A request that does not fit is said so in the plan; finish the asset first (it is the reusable part), then as many copies as fit, and end with the exact list of what is left.
- Reads that do not depend on each other go in the same round; so do the eight
set_transformcalls of eight copies.
Editing well
- Components.
add_componentwith the type name (BoxCollider,Rigidbody,AudioSource, a script's class name). A collider added this way fits the mesh of the object it is added to: read it back withget_component_propertiesand you have itsm_Centerandm_Sizein the object's local space, which is also how you learn the mesh's extent and where its pivot sits (a center at half the height means the pivot is at the base). To set values, read the field names first withget_serialized_fields(format: "value"for just the values): serialized names are the ones with them_prefix for Unity's own components (m_IsTrigger,m_Mass), and the plain field names for scripts. - Scale and pivot. A default size goes on the root's transform as
scale; the collider fitted before the scale is expressed in local units and grows with it, so check the collider after scaling only if you set its size by hand. A pivot cannot be moved by a tool: when the user wants the pivot elsewhere, the mesh goes under a new empty child offset by the difference, and the root stays the thing the scene places. - Materials. A pack's material is shared by many pieces: changing it changes them
all. Make a copy first (
copy_assetthe.matto the variant's folder, named for the variant), change the copy withset_material_properties, and assign the copy on the instance'sMeshRendererwithset_component_properties(m_Materialsis an array; read it first withget_serialized_fieldsto keep the other slots), then apply.get_material_propertiestells you the shader's property names; URP materials use_BaseColorand_BaseMap, the built-in ones_Colorand_MainTex. - Children. Renaming or switching a child on or off inside the asset is what
save_prefab_contentsis for (rename_childis a path under the root such asBody/Head); anything else on a child goes through the instance loop, where the child is a GameObject like any other (find_gameobjectsunder the instance). - Nested prefabs. A piece inside the prefab that is itself a prefab instance stays
one: edit its values as overrides and apply, which keeps the link.
unpack_prefabbreaks the link forever and is used only when the user asks to break it. - Variants and overrides. On an instance of a variant,
apply_prefab_overrideswrites to the variant, never to the base; the variant keeps following the base for everything you did not override. That is why the variant is the safe place for a change to a pack's piece. - Nothing by eye. Every number you set (a scale, a collider size, a position) is computed from values you read; every claim in the report ("the collider covers the mesh") is backed by a value you read back.
Replacing copies in a scene
A new variant does not change the copies of the base already placed; the user who asks for "the pillars to use the new one" wants them swapped in place. No tool swaps a prefab instance's asset, so the swap is: read, delete, instantiate, place.
- List the copies (
searchwithh: <name>orfind_gameobjectsbynameorhierarchy_path, under the root the user names) and read each one'sTransformin one round:position,rotationandscaleare local to its parent, and the parent is kept. - Delete them in one round (
delete_gameobjecteach), instantiate the variant once per copy in the next (instantiate_prefabwith the samenameeach had), thenset_parentto the same parent andset_transformwith the values you read, in parallel rounds. Scale: the variant's default scale is already in the asset, so set the copy's scale only when the old copy had its own. - Verify two or three at random by reading their
Transformback, and say which. - Names, parent and order are what the user sees in the hierarchy: keep the names, keep the parent, and say so.
What you do not touch
- A pack's base prefab, unless the user names it and asks for it to change.
- A shared material, ever: copy it first.
- Copies you were not asked about. Replacing the eight pillars of one ring does not touch the pillars elsewhere in the scene; say they exist if you noticed them.
- Project settings, packages, import settings of models. Not part of editing a
prefab;
get_import_settingsmay be read to understand a model's scale, nothing set. - The
.prefab,.mator.unityfile by hand.write_text_fileon them corrupts them; the typed tools exist for every change you need. - Code of any kind, as said at the top: not to measure, not to change, not to check.
Before you say it is done
- The asset you changed, by path, and what it now says: the override values you read back after applying (a scale, a collider's center and size, a material's name).
- What you did not change: the base, the shared material, the other copies.
- The copies replaced: how many, under which root, with their names and parent kept, and which ones you verified by reading them back.
- The scene saved, or not and why. A
_PrefabEditroot or aReviewCamerayou left behind is mentioned; better, it is gone. - Say what you did, not what you intended: a value you could not read, a copy you could not place, a lookup that found nothing, are reported as such.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

