From f767d15d21ebbf4948a4ae503b53323d3443ee87 Mon Sep 17 00:00:00 2001 From: Andrew Skowronski Date: Fri, 16 Oct 2026 10:09:01 -0400 Subject: [PATCH 1/3] Document circular reference handling in content directory builds for Unity 6.6 and 6.7 --- Documentation/contentdirectory-format.md | 66 +++++++++++++++++++++--- 1 file changed, 60 insertions(+), 6 deletions(-) diff --git a/Documentation/contentdirectory-format.md b/Documentation/contentdirectory-format.md index 64656ba..3ea2b98 100644 --- a/Documentation/contentdirectory-format.md +++ b/Documentation/contentdirectory-format.md @@ -109,12 +109,9 @@ few grouping rules shape the result: File, just as they are represented in the Editor (see [Scenes](#scenes) below). - **Assets with sub-assets** are split across multiple Content Files. For example an FBX is separated so that the component hierarchy and the meshes land in different files. -- **Scripts** are grouped: the `MonoScript` objects for several source scripts can share one Content - File. -- **Circular direct references are best avoided.** Currently a cycle forces all the affected Unity - objects to be clustered together into a single Content File, and the build prints a warning. The way - to break a cycle is to convert one of the references into a `Loadable` (an on-demand reference) - instead of a direct reference. +- **Scripts** are grouped: all the `MonoScript` objects in the build share a single Content File. +- **Circular direct references are best avoided.** How a cycle shows up in the build output depends + on the Unity version — see [Circular references](#circular-references) below. Unity's two built-in resource files are handled in different ways: @@ -130,6 +127,63 @@ Unity's two built-in resource files are handled in different ways: contains only the project's "Always Included Shaders" — copying the referenced objects into the content directory makes it independent of what a particular Player build happens to contain. +### Circular references + +A circular reference is a loop of direct references between objects that the rules above would place +in different Content Files — for example two ScriptableObject assets that reference each other, or a +Prefab whose component references a ScriptableObject that references the Prefab back. Only direct +references count: a `Loadable` or `LoadableSceneId` reference does not create a dependency between +files, so converting one of the references in the loop into a `Loadable` breaks the cycle. Scenes +are never part of a cycle, because Unity does not support direct references to objects inside a +scene. + +**Unity 6.6** merges each cycle at build time. All the objects that would have formed the loop are +written into a single Content File, so the dependencies between Content Files never contain a cycle. +In [`ContentLayout.json`](contentlayout.md) the merged file is one `SerializedFiles` entry whose +`SourceAssets` lists every asset in the loop. The build prints a warning that it detected circular +reference loops, and the Editor log lists the assets involved in each one. A long chain of references +can pull many assets into one unexpectedly large Content File, and loading any of them loads them all. + +**Unity 6.7** keeps the normal granular layout. Each asset in the loop stays in its own Content File +and the files reference each other in a cycle, which is visible in `ContentLayout.json` as +`SerializedFileDependencies` that lead back to the starting file. At runtime the files in a cycle are +loaded together as a single unit: loading any one of them loads all of them, and this is more +resource-intensive than loading files individually. The build prints a warning when it finds a cycle, +and fails if the combined size of the Content Files in a single cycle exceeds a limit (currently +64 MB). + +Unity 6.7 also writes a `circularrefs.json` file to the build's directory in the +[build history](#build-history), listing each cycle with its files. A common pattern is a Prefab +that references a definition asset which references the Prefab back: + +```json +{ + "clusters": [ + { + "fileCount": 2, + "combinedSizeBytes": 22656, + "files": [ + { + "fileId": "3c9e1f0a7b2d48e6a15f0c8d9e2b4a71", + "guid": "3c9e1f0a7b2d48e6a15f0c8d9e2b4a71", + "path": "Assets/Items/Crate.prefab" + }, + { + "fileId": "8d4a62b0e9f1475c9b3e1a0f6c7d2e58", + "guid": "8d4a62b0e9f1475c9b3e1a0f6c7d2e58", + "path": "Assets/Items/Definitions/Crate.asset" + } + ] + } + ] +} +``` + +The file is written for every build, with an empty `clusters` array when there are no cycles. Each +`fileId` is the file's `StableId` in `ContentLayout.json`, and `path` is the source asset the Content +File was built from. In a large project this file is worth checking: it can list hundreds of cycles, +and a single cycle can span hundreds of files. + ## Scenes Content directory builds can include Unity Scenes. The build parameters only accept ScriptableObject From 274171384ca0b552cde59e109ecad6122038f575 Mon Sep 17 00:00:00 2001 From: Andrew Skowronski Date: Fri, 16 Oct 2026 10:17:08 -0400 Subject: [PATCH 2/3] Note ContentLayout excerpt schema version; clarify which dependency graph can be cyclical --- Documentation/contentdirectory-format.md | 4 ++++ Documentation/contentlayout.md | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/contentdirectory-format.md b/Documentation/contentdirectory-format.md index 3ea2b98..bb92176 100644 --- a/Documentation/contentdirectory-format.md +++ b/Documentation/contentdirectory-format.md @@ -21,6 +21,10 @@ The output can be written as loose files or packed into a Unity Archive, so Unit same way it opens Player and AssetBundle content. An example build, used for testing, can be found in `TestCommon/Data/LeadingEdgeBuilds/ContentDirectory`. +The `ContentLayout.json` excerpts on this page come from its layout in +`TestCommon/Data/LeadingEdgeBuilds/BuildReport-ContentDirectory`, which uses the version 3 schema +written by Unity 6.7. Unity 6.6 writes version 2, which names some fields differently — see +[Schema versioning](contentlayout.md#schema-versioning). The files use technical, content-hash-based names, rather than the familiar `level0` / `sharedassets` names of a Player build or the user-specified names of AssetBundles. You do not need to understand the diff --git a/Documentation/contentlayout.md b/Documentation/contentlayout.md index 981ab32..917c305 100644 --- a/Documentation/contentlayout.md +++ b/Documentation/contentlayout.md @@ -64,7 +64,9 @@ resource path (`Library/unity default resources`) as its stable id. * `BinaryArtifacts` also reports the additional data files that hold audio, video, texture, and mesh data (the `.resource` and `.resS` files). * BinaryArtifacts are identified by the hash of their content. When saved as a file, the filename is the hash and the file extension is based on the category. -`ArtifactReferences` lists only direct dependencies. Dependencies that go through a loadable or loadable scene are not included, and the dependency graph is never cyclical. Together, this makes it possible to see every artifact required to load a particular serialized file, excluding data that is loaded on demand through a loadable or loadable scene. +`ArtifactReferences` lists only direct dependencies. Dependencies that go through a loadable or loadable scene are not included, and the `ArtifactReferences` graph is never cyclical. Together, this makes it possible to see every artifact required to load a particular serialized file, excluding data that is loaded on demand through a loadable or loadable scene. + +The dependencies between serialized files (`SerializedFileDependencies`) can contain cycles in builds from Unity 6.7, where assets that reference each other in a loop keep their own serialized files. See [Circular references](contentdirectory-format.md#circular-references). ## Schema versioning From dcc8399b8556839ae3ff379ac2282afec0f921f3 Mon Sep 17 00:00:00 2001 From: Andrew Skowronski Date: Fri, 16 Oct 2026 11:53:18 -0400 Subject: [PATCH 3/3] Clarify that ArtifactReferences excludes dependencies between serialized files --- Documentation/contentlayout.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/contentlayout.md b/Documentation/contentlayout.md index 917c305..4f0d0b5 100644 --- a/Documentation/contentlayout.md +++ b/Documentation/contentlayout.md @@ -64,9 +64,9 @@ resource path (`Library/unity default resources`) as its stable id. * `BinaryArtifacts` also reports the additional data files that hold audio, video, texture, and mesh data (the `.resource` and `.resS` files). * BinaryArtifacts are identified by the hash of their content. When saved as a file, the filename is the hash and the file extension is based on the category. -`ArtifactReferences` lists only direct dependencies. Dependencies that go through a loadable or loadable scene are not included, and the `ArtifactReferences` graph is never cyclical. Together, this makes it possible to see every artifact required to load a particular serialized file, excluding data that is loaded on demand through a loadable or loadable scene. +`ArtifactReferences` does not record dependencies between serialized files. The dependencies that come from objects with direct (PPtr) references to objects in other serialized files are listed only in the `SerializedFiles` entries, in `SerializedFileDependencies`. A `contentfile` artifact's `ArtifactReferences` lists only the `.resS` and `.resource` data files its objects use. It never lists another `contentfile`, and the data files are leaf nodes with no dependencies of their own. By design the `ArtifactReferences` graph never contains cycles, and this will stay true if more categories of data are added in the future. -The dependencies between serialized files (`SerializedFileDependencies`) can contain cycles in builds from Unity 6.7, where assets that reference each other in a loop keep their own serialized files. See [Circular references](contentdirectory-format.md#circular-references). +To find every artifact required to load a serialized file, follow its `SerializedFileDependencies` recursively to the other serialized files it needs, and collect each file's artifact (through `ArtifactIndex`) together with that artifact's `ArtifactReferences`. Dependencies that go through a loadable or loadable scene are not included in either list, because that data is loaded on demand. Unlike `ArtifactReferences`, `SerializedFileDependencies` can contain cycles in builds from Unity 6.7, where assets that reference each other in a loop keep their own serialized files. See [Circular references](contentdirectory-format.md#circular-references). ## Schema versioning