This page explains which elements a .mochi.xml is made of, what each becomes in Unity, and in what order they are expanded. The rules for each element are in Element reference, and how to write attribute values is in Value grammar.
Elements fall into the following 6 categories, by what they create in Unity.
Category
Meaning
Elements
Root element
The top-level element of a file. Its name is the part’s name; in an entry point, it becomes the prefab’s root GameObject
A tag named after the part
Host
An element that creates one GameObject. Accepts common attributes such as name and position
<Object>, <Row>, <Grid>, <Prefab>, part tags
Component tag
An element that adds a component to its parent GameObject. Its name is the Unity component’s type name
<MeshRenderer>, <Light>, and so on
Control
An element that expands its content once per data row, or only when a condition is true. It creates nothing itself
<For>・<If>
Declaration
An element that declares the props a part receives. It creates nothing
<Props>・<Prop>
Insertion
An element that marks where content goes. <Slot> receives content written by the caller, and <At> points to a GameObject inside a prefab. It creates nothing itself
One .mochi.xml file. The file name without .mochi.xml is the part’s name, and the root element has the same name
Using a part
Write the part’s name as a tag. One GameObject is created where it’s used, and the contents of the part’s file (except <Props>) become its children
props
The part’s arguments. The part declares names, types, and default values with <Prop> in <Props>, and the caller passes values by writing prop names as attributes on the part tag
Rules for passing props
As with function arguments, an undeclared name can’t be passed (MOCHI3005), and a prop without default can’t be left out (MOCHI3008). Common host attributes (name, position, and so on) aren’t props; they become attributes of the GameObject where the part is used
Entry points
A part whose root element has prefab="true". Saving generates one prefab from this file. It can also be used as a part from other files
An entry point’s props
There’s no caller to pass values, so every prop needs a default
Only in attributes. There’s no way to write a value as text inside an element or as a child element
Types
Fixed per attribute (position is a Vector3, active is a bool, and so on). The written text is read as a value of that type
Binding
Writing the whole value as {name} or {row.column} reads the value of a prop or a <For> row. It can’t appear partway through text
Common host attributes
14 attributes such as name, key, and position. A GameObject with a RectTransform gives its position and size with the RectTransform attributes (GameObjects with a RectTransform)
Element-specific attributes
<Prefab src>, <For each>, <Row spacing>, and so on
Attributes of a part tag
The common host attributes and the props that part declares
Attributes of a component tag
The C# property names of the Unity component (<Light intensity="2"/>)
The slot attribute
Written on a child of a part tag to choose which <Slot> that child goes to
Values fixed at generation time and values that change at runtime
A value fixed when you save in Unity and the prefab is generated, and written into the prefab. Constants, props without runtime, and <For> rows are all of this kind
<For> and <If>
Expanded at generation time. The number of rows and the conditions don’t change while the world runs
Value that changes at runtime
A value bound, inside a part with a T# script, to a prop with runtime="true" or to a C# member of that part
Where a value that changes at runtime can be written
Only active and props with runtime="true". Other attributes give MOCHI5004, and <If test> gives MOCHI5003 (Value that changes at runtime)