YAML serialization of prefabs
Understand how prefab instances, nested prefabs, and prefab variants are represented in YAML.
Read time 6 minutesLast updated 24 days ago
Unity represents prefab instances, nested prefabs, and prefab variants in serialized scene () and prefab () files using a small set of related YAML elements. This page describes those elements and how they fit together.
.unity.prefabUnderstanding this format is useful when you resolve merge conflicts in prefab files manually, inspect files produced by an automated build, or work with Unity assets from scripts that run outside the Editor.
For general information about Unity serialization format, refer to Format of text serialized files and UnityYAML. For annotated YAML examples from prefab files, refer to Example of YAML prefab serialization.
Prefab serialization elements
Unity represents a reference to a prefab inside a scene or another prefab file using four related elements:
- A PrefabInstance YAML element that links to the source prefab asset and records a set of override changes.
- An m_Modification block inside the element that records individual property modifications and the objects added or removed relative to the source prefab.
PrefabInstance - Stripped placeholder objects that let other objects in the same file reference specific objects inside the prefab instance (such as a child ).
Transform - A prefab asset handle in the source prefab asset. Its fileID is always , and
100100000objects reference it through thePrefabInstanceproperty.m_SourcePrefab
For information on how these elements are arranged in prefab variant files, refer to Prefab variants.
PrefabInstance element
Unity represents a prefab instance as a YAML document with class ID and document type :
1001PrefabInstance--- !u!1001 &<fileID>PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: ... m_SourcePrefab: {fileID: 100100000, guid: <prefab-guid>, type: 3}
The key properties are:
- : a block of data that records everything that differs between this instance and the source prefab. For more information, refer to The m_Modification block.
m_Modification - : a cross-file reference to the source prefab asset. The fileID is always
m_SourcePrefab(the prefab asset handle), so only the100100000value varies between references. For more information, refer to The prefab asset handle.guid
For a complete example of a prefab instance in a scene, refer to Prefab instance in a scene.
The m_Modification block
The block stores data that differs between the instance and the source prefab, including property overrides and any objects that are added or removed. It has the following fields:
m_ModificationField | Description |
|---|---|
| Reference to this instance's parent |
| Array of property override entries. Each entry points to an object in the source prefab and records a new value for one property. For more information, refer to Property modifications. |
| Components from the source prefab that are removed in this instance. |
| GameObjects from the source prefab that are removed in this instance. |
| GameObjects added to this instance that don't exist in the source prefab. |
| Components added to this instance that don't exist in the source prefab. |
Unity writes empty lists for any of these fields even when there are no entries. A clean prefab instance with no overrides still contains , , and so on.
m_Modifications: []m_RemovedComponents: []Property modifications
Each entry in the array has four fields:
m_ModificationsField | Description |
|---|---|
| Cross-file reference to the object inside the source prefab whose property this entry overrides. The |
| Path to the property being overridden. Matches |
| The override value, stored as a string. Empty for object-reference overrides. |
| Reference to another object when the override value is a reference. |
A typical property override uses the field:
value- target: {fileID: 599465214307944399, guid: 95cf80858ee0c4940b72f62b17aefd41, type: 3} propertyPath: m_LocalPosition.x value: 39.341 objectReference: {fileID: 0}
An object-reference override uses instead, with an empty field:
objectReferencevalue- target: {fileID: 1773024279374141337, guid: 89d4c08db6b9096438cb6c7718d47f26, type: 3} propertyPath: m_Material value: objectReference: {fileID: 2100000, guid: 31321ba15b8f8eb4c954353edc038b1d, type: 2}
For more information about the format in references, refer to Direct reference asset management.
{fileID, guid, type}Stripped placeholder objects
A scene file or a containing prefab file can reference specific objects inside a prefab instance. For example, if a prefab instance's root is a child of a GameObject in the scene, the parent GameObject's component contains the prefab instance's root in its array.
Transformm_ChildrenIn these cases, Unity doesn't serialize the referenced object directly into the scene or containing prefab file. Instead, it adds a stripped placeholder element to that file. The placeholder contains only the information needed to identify the source object:
--- !u!4 &<fileID> strippedTransform: m_CorrespondingSourceObject: {fileID: <source-fileID>, guid: <source-guid>, type: 3} m_PrefabInstance: {fileID: <PrefabInstance-fileID>} m_PrefabAsset: {fileID: 0}
The keyword on the document header indicates that the object is a placeholder. The fields are:
strippedField | Description |
|---|---|
| Cross-file reference to the matching object in the source prefab asset. |
| Local reference to the |
| Has the value |
The prefab asset handle
When Unity imports a asset, it creates a special object called the prefab asset handle with fileID . The handle doesn't appear as a YAML document in the source file on disk. It's generated during import and is stored in the prefab's serialized artifact in the folder.
.prefab100100000.prefabLibraryThe handle is the target of the reference on a :
m_SourcePrefabPrefabInstancem_SourcePrefab: {fileID: 100100000, guid: 95cf80858ee0c4940b72f62b17aefd41, type: 3}
Because fileID is constant for every prefab, only the changes between references to different prefabs. The indicates that the reference resolves to the imported artifact in the folder rather than to a file in the folder. For more information about type values, refer to Type field values.
100100000guidtype: 3LibraryAssetsPrefab variants
A prefab variant is a file that inherits from a base prefab.
.prefabOn disk, Unity represents a prefab variant's root as a element (class ID ) rather than as a separately serialized element. Inside that , the field has the value , because the instance has no parent inside the file. This is how Unity identifies a prefab as a variant.
PrefabInstance1001GameObjectPrefabInstancem_Modification.m_TransformParent{fileID: 0}The field references the base prefab that the variant inherits from. The block records the data unique to the variant, such as overridden property values, components, and added or removed objects, using the same format as any other prefab instance.
m_SourcePrefabm_ModificationFor an annotated example of a variant file, refer to Prefab variant.