Magica Cloth 2 (code-first authoring via Unity MCP)
Set up and tune cloth simulation on a Unity character without clicking the
Inspector — by running C# in the Editor through the Unity MCP Unity_RunCommand
tool. Magica Cloth 2 exposes its entire config as a public ClothSerializeData
plus a BuildAndRun() entry point, so every Inspector action is reproducible from
script. This is validated ground truth on v2.8.0 (full C# source under
Assets/Plugins/MagicaCloth2/).
The look lives in authored data (cloth type, vertex/bone selection, collider
placement, constraint curves), not in code. Plan the data first; the solver is fixed.
Prerequisites (verify, else stop)
- Magica Cloth 2 present.
Assets/Plugins/MagicaCloth2/ (or a UPM package). Check
the version in .../Editor/EditorExtension/AboutMenu.cs — feature gating depends on it.
- Unity MCP connected.
Unity_RunCommand, Unity_ManageEditor, Unity_ReadConsole
available. If not, stop and tell the user.
- Target character with a humanoid/skeleton rig and SkinnedMeshRenderer(s). For
MeshCloth, the source mesh must be Read/Write ON and Optimize GameObjects OFF.
Decision: pick the cloth type first
Everything downstream depends on this. See pipeline.md for internals.
| Type |
Simulates |
Use for |
Selection data |
Cost |
| BoneCloth |
Transform chains |
hair, tails, cords, skirts with bones |
auto (root=Fixed, rest=Move) |
low |
| MeshCloth |
mesh vertices (proxy) |
skirts/capes without bones, on the skinned mesh |
mandatory (else nothing moves) |
high — desktop/console |
| BoneSpring |
spring on Transforms |
chest/butt jiggle, soft secondary motion |
auto |
low |
The #1 gotcha: MeshCloth auto-selection fills every vertex Invalid → the cloth
does nothing. You must supply selection data (paint, paint map, or attribute array).
BoneCloth/BoneSpring auto-generate a usable selection. Prefer BoneCloth for new
elements when bones exist; reserve MeshCloth for boneless geometry on the body mesh.
Quick start — BoneCloth from script (runtime build)
Run via Unity_RunCommand (class must be internal CommandScript : IRunCommand).
Build (BuildAndRun) only runs in Play mode; in edit mode just set data and let
Start() auto-build at play. Full MCP recipes (edit-mode authoring that persists,
copying an existing setup, colliders, re-targeting) are in
mcp-authoring.md.
using MagicaCloth2; using UnityEngine; using Unity.Mathematics;
internal class CommandScript : IRunCommand {
public void Execute(ExecutionResult result) {
var go = GameObject.Find("Character/Hair");
var cloth = go.AddComponent<MagicaCloth>();
var sd = cloth.SerializeData;
sd.clothType = ClothProcess.ClothType.BoneCloth; // [NG] runtime: set before build
sd.rootBones.Add(GameObject.Find("hair_root_L").transform);
sd.gravity = 3.0f;
sd.damping.SetValue(0.05f);
sd.angleRestorationConstraint.stiffness.SetValue(0.15f, 1.0f, 0.15f, true);
sd.colliderCollisionConstraint.mode = ColliderCollisionConstraint.Mode.Point;
result.RegisterObjectCreation(go); // undo tracking
// cloth.BuildAndRun(); // only in Play mode; otherwise Start() auto-builds
}
}
Workflow
- Inspect. Read the rig, renderers, existing cloth/colliders with a lightweight
Unity_RunCommand (component type names only — never dump SkinnedMeshRenderer data,
it crashes Unity). See pitfalls.md.
- Choose type (table above). Confirm Read/Write for MeshCloth.
- Colliders first. Add
MagicaCapsuleCollider/MagicaSphereCollider on body bones
(thighs, hips, head, chest). Uniform global scale only or collision fails.
- Author the cloth. Set
SerializeData; for MeshCloth also supply selection data.
Register colliders in colliderCollisionConstraint.colliderList.
- Parameters. Start from a preset, then tune Angle Restoration first (it dominates
motion), then Inertia, then collision. Calibration table in parameters.md.
For a stylized cel-shaded / anime look (readable, bounded, snappy secondary motion), use the
bone-based types and the tuning recipe in parameters.md.
- Build & test. Enter Play (
Unity_ManageEditor Play), confirm each cloth
IsValid()==true, capture the scene, compare. See mcp-authoring.md.
- Verify console (mandatory):
Unity_ReadConsole with Types:["Error","Warning","Log"],
grep error CS / Exception. Fix before declaring done.
Runtime-change rule
[NG] fields (set before build, never after): clothType, sourceRenderers,
rootBones, connectionMode.
[OK] fields (gravity, radius, damping, constraints): after changing at runtime, call
cloth.SetParameterChange(). After changing a live collider, call collider.UpdateParameters().
Reference map
| File |
Covers |
| mcp-authoring.md |
Unity_RunCommand patterns, edit-mode persist via LoadPrefabContents, copy+re-target an existing setup, collider creation, selection-data generation, Play-mode testing & scene capture |
| parameters.md |
Every constraint (Force, Angle Restoration/Limit, Distance/Tether/Bending, Inertia, Collision, Self-Collision, Spring), calibration numbers, presets, stylized anime-look recipe, penetration fixes, wind |
| pipeline.md |
How the solver works (PBD-style, 90 Hz substeps, constraint order), update modes, culling, pre-build, v2.8.0 feature gating |
| pitfalls.md |
Failure modes (symptom → cause → fix): Unity crashes, MeshCloth dead, clipping, jitter, scale, update-mode oscillation |
Version note
This skill is validated on 2.8.0. Absent before later versions: distance culling
(2.10), collider symmetry ColliderSymmetryMode (2.15), batch jobs (2.14). Camera
culling, self-collision, and pre-build are present. Check AboutMenu.cs and confirm an API
exists before using it; see pipeline.md.
1---2name: magica-cloth-23description: Author and tune cloth physics with Magica Cloth 2 in Unity, code-first via the Unity MCP (Unity_RunCommand) — BoneCloth / MeshCloth / BoneSpring setup, capsule/ sphere/plane colliders, constraint parameters, runtime build, and in-editor visual testing. Use when adding or fixing cloth/jiggle on a character (skirt, hair, cape, tail, chest, accessories), when cloth clips through the body, jitters, feels too stiff/floppy, penetrates on fast motion, or when the user mentions Magica Cloth, MagicaCloth, cloth simulation, or dynamic bones in a Unity project.4---56# Magica Cloth 2 (code-first authoring via Unity MCP)78Set up and tune cloth simulation on a Unity character **without clicking the9Inspector** — by running C# in the Editor through the Unity MCP `Unity_RunCommand`10tool. Magica Cloth 2 exposes its entire config as a public `ClothSerializeData`11plus a `BuildAndRun()` entry point, so every Inspector action is reproducible from12script. This is validated ground truth on **v2.8.0** (full C# source under13`Assets/Plugins/MagicaCloth2/`).1415The look lives in **authored data** (cloth type, vertex/bone selection, collider16placement, constraint curves), not in code. Plan the data first; the solver is fixed.1718## Prerequisites (verify, else stop)19201. **Magica Cloth 2 present.** `Assets/Plugins/MagicaCloth2/` (or a UPM package). Check21 the version in `.../Editor/EditorExtension/AboutMenu.cs` — feature gating depends on it.222. **Unity MCP connected.** `Unity_RunCommand`, `Unity_ManageEditor`, `Unity_ReadConsole`23 available. If not, stop and tell the user.243. **Target character** with a humanoid/skeleton rig and SkinnedMeshRenderer(s). For25 MeshCloth, the source mesh must be **Read/Write ON** and **Optimize GameObjects OFF**.2627## Decision: pick the cloth type first2829Everything downstream depends on this. See [pipeline.md](./pipeline.md) for internals.3031| Type | Simulates | Use for | Selection data | Cost |32| --- | --- | --- | --- | --- |33| **BoneCloth** | Transform chains | hair, tails, cords, skirts **with bones** | auto (root=Fixed, rest=Move) | low |34| **MeshCloth** | mesh vertices (proxy) | skirts/capes **without bones**, on the skinned mesh | **mandatory** (else nothing moves) | high — desktop/console |35| **BoneSpring** | spring on Transforms | chest/butt jiggle, soft secondary motion | auto | low |3637**The #1 gotcha:** MeshCloth auto-selection fills every vertex `Invalid` → the cloth38does nothing. You **must** supply selection data (paint, paint map, or attribute array).39BoneCloth/BoneSpring auto-generate a usable selection. Prefer **BoneCloth** for new40elements when bones exist; reserve MeshCloth for boneless geometry on the body mesh.4142## Quick start — BoneCloth from script (runtime build)4344Run via `Unity_RunCommand` (class **must** be `internal CommandScript : IRunCommand`).45Build (`BuildAndRun`) only runs in **Play mode**; in edit mode just set data and let46`Start()` auto-build at play. Full MCP recipes (edit-mode authoring that persists,47copying an existing setup, colliders, re-targeting) are in48[mcp-authoring.md](./mcp-authoring.md).4950```csharp51using MagicaCloth2; using UnityEngine; using Unity.Mathematics;52internal class CommandScript : IRunCommand {53 public void Execute(ExecutionResult result) {54 var go = GameObject.Find("Character/Hair");55 var cloth = go.AddComponent<MagicaCloth>();56 var sd = cloth.SerializeData;57 sd.clothType = ClothProcess.ClothType.BoneCloth; // [NG] runtime: set before build58 sd.rootBones.Add(GameObject.Find("hair_root_L").transform);59 sd.gravity = 3.0f;60 sd.damping.SetValue(0.05f);61 sd.angleRestorationConstraint.stiffness.SetValue(0.15f, 1.0f, 0.15f, true);62 sd.colliderCollisionConstraint.mode = ColliderCollisionConstraint.Mode.Point;63 result.RegisterObjectCreation(go); // undo tracking64 // cloth.BuildAndRun(); // only in Play mode; otherwise Start() auto-builds65 }66}67```6869## Workflow70711. **Inspect.** Read the rig, renderers, existing cloth/colliders with a *lightweight*72 `Unity_RunCommand` (component type names only — never dump SkinnedMeshRenderer data,73 it crashes Unity). See [pitfalls.md](./pitfalls.md).742. **Choose type** (table above). Confirm Read/Write for MeshCloth.753. **Colliders first.** Add `MagicaCapsuleCollider`/`MagicaSphereCollider` on body bones76 (thighs, hips, head, chest). **Uniform global scale only** or collision fails.774. **Author the cloth.** Set `SerializeData`; for MeshCloth also supply selection data.78 Register colliders in `colliderCollisionConstraint.colliderList`.795. **Parameters.** Start from a preset, then tune Angle Restoration first (it dominates80 motion), then Inertia, then collision. Calibration table in [parameters.md](./parameters.md).81 For a stylized cel-shaded / anime look (readable, bounded, snappy secondary motion), use the82 bone-based types and the tuning recipe in [parameters.md](./parameters.md#stylized-anime-look-tuning-recipe).836. **Build & test.** Enter Play (`Unity_ManageEditor` Play), confirm each cloth84 `IsValid()==true`, capture the scene, compare. See [mcp-authoring.md](./mcp-authoring.md).857. **Verify console** (mandatory): `Unity_ReadConsole` with `Types:["Error","Warning","Log"]`,86 grep `error CS` / `Exception`. Fix before declaring done.8788## Runtime-change rule8990- `[NG]` fields (set **before** build, never after): `clothType`, `sourceRenderers`,91 `rootBones`, `connectionMode`.92- `[OK]` fields (gravity, radius, damping, constraints): after changing at runtime, call93 `cloth.SetParameterChange()`. After changing a live collider, call `collider.UpdateParameters()`.9495## Reference map9697| File | Covers |98| --- | --- |99| [mcp-authoring.md](./mcp-authoring.md) | `Unity_RunCommand` patterns, edit-mode persist via `LoadPrefabContents`, copy+re-target an existing setup, collider creation, selection-data generation, Play-mode testing & scene capture |100| [parameters.md](./parameters.md) | Every constraint (Force, Angle Restoration/Limit, Distance/Tether/Bending, Inertia, Collision, Self-Collision, Spring), calibration numbers, presets, **stylized anime-look recipe**, penetration fixes, wind |101| [pipeline.md](./pipeline.md) | How the solver works (PBD-style, 90 Hz substeps, constraint order), update modes, culling, pre-build, **v2.8.0 feature gating** |102| [pitfalls.md](./pitfalls.md) | Failure modes (symptom → cause → fix): Unity crashes, MeshCloth dead, clipping, jitter, scale, update-mode oscillation |103104## Version note105106This skill is validated on **2.8.0**. Absent before later versions: **distance culling**107(2.10), **collider symmetry** `ColliderSymmetryMode` (2.15), **batch jobs** (2.14). Camera108culling, self-collision, and pre-build are present. Check `AboutMenu.cs` and confirm an API109exists before using it; see [pipeline.md](./pipeline.md).