Skip to content

[#81] Fix scene/preload dependencies for Player and Scriptable Build Pipeline builds#87

Merged
SkowronskiAndrew merged 5 commits into
mainfrom
issue81-fix-preload-dependencies
Jul 6, 2026
Merged

[#81] Fix scene/preload dependencies for Player and Scriptable Build Pipeline builds#87
SkowronskiAndrew merged 5 commits into
mainfrom
issue81-fix-preload-dependencies

Conversation

@SkowronskiAndrew

Copy link
Copy Markdown
Collaborator

Summary

Fixes #81.

analyze mis-recorded scene/preload dependencies for every build except BuildPipeline.BuildAssetBundles. Both symptoms shared one root cause — a synthetic "Scene" object (and a valid SceneId) was only created when a SerializedFile was named BuildPlayer-<SceneName>. This PR fixes both cases.

Changes

Player builds (preload_dependencies.object was -1)

A player build has no scene object, but it still contains PreloadData objects (one per scene in sharedassetsN.assets, plus one in globalgamemanagers.assets). Their dependencies were all attributed to object id -1.

  • PreloadDataHandler now attributes the dependencies to the PreloadData object itself when there is no scene (object = SceneId != -1 ? SceneId : objectId).

Scriptable Build Pipeline / Addressables scene bundles (dangling scene rows)

SBP/Addressables name scene files CAB-<hash> / CAB-<hash>.sharedAssets, which the BuildPlayer- regex never matched, so no Scene object was created: the assetbundle_assets rows for scenes dangled and the scene→dependency relationship was lost.

  • AssetBundle.cs now parses the AssetBundle object's m_SceneHashes (scene path → scene SerializedFile), guarded for builds that don't emit it.
  • AssetBundleHandler creates one synthetic Scene object per scene, keyed on the scene's SerializedFile, plus its assetbundle_assets row.
  • SerializedFileSQLiteWriter resolves the same scene object id for a <file>.sharedAssets file, so PreloadDataHandler and the scene-content loop attach the scene's dependencies to it. The id is derived deterministically from the file name, so it is independent of the order in which files are processed (the AssetBundle object may come after the scene files).

The scene's own content objects (GameObjects, etc.) are not listed as preload_dependencies but share the scene object's serialized_file.

Docs / comments

  • Documentation/analyzer.md: reworked the preload_dependencies / preload_dependencies_view / assetbundle_asset_view sections to describe the per-build behaviour and removed the issue-81 "known limitation" notes. Dependencies can still legitimately dangle when they reference objects analyze never tracked (e.g. unity default resources), which is documented.

Testing

  • dotnet test — full suite green: 236 (UnityDataTool.Tests) + 62 (Analyzer.Tests).
  • New tests: AnalyzeSceneBundleTests (scene resolves, no dangling assetbundle_assets, dependencies present in preload_dependencies_view) and, from the player-build fix, Analyze_PlayerDataPreloadDependencies_ObjectResolvesToRealObject.
  • Manual verification on a large Addressables build: 261 dangling .unity scene rows → 0, 261 synthetic Scene objects created, and all 261 scenes now show their dependencies in preload_dependencies_view; overall row counts matched the pre-fix database plus exactly the expected additions.

Follow-up

The repo has no small SBP/Addressables scene-bundle fixture, so the automated scene test uses a BuildPipeline.BuildAssetBundles bundle and the SBP path was verified manually. Adding SBP test data is tracked in #86.

…builds

Also flesh out the documentation for these tables to precisely explain what they contain
SBP/Addressables name scene files "CAB-<hash>" (and "CAB-<hash>.sharedAssets"),
which the BuildPlayer- scene regex never matched, so no synthetic Scene object
was created: assetbundle_assets scene rows dangled and the scene->dependency
relationship was lost.

Use the AssetBundle object's m_SceneHashes (scene path -> scene SerializedFile)
to key a synthetic Scene object on the scene's file. AssetBundleHandler creates
that object and its assetbundle_assets row; SerializedFileSQLiteWriter resolves
the same id for a "<file>.sharedAssets" file so PreloadDataHandler and the
content loop attach the scene's dependencies to it. Order-independent because the
id is derived deterministically from the file name.

Adds a scene-bundle analyze regression test. SBP-specific fixture data is tracked
separately (issue #86); the SBP path was verified manually against a large
Addressables build.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect scene/preload dependency recording in analyze for Player builds and Scriptable Build Pipeline (SBP)/Addressables scene bundles by ensuring a stable synthetic “Scene” object is created/resolved across build types, and by attributing Player preload dependencies to a real object.

Changes:

  • Fix Player builds so PreloadData dependencies attach to the PreloadData object when no scene object exists.
  • Add SBP/Addressables scene support by parsing AssetBundle.m_SceneHashes, synthesizing Scene objects keyed to the scene SerializedFile, and resolving the same scene id for .sharedAssets.
  • Add regression tests and update analyzer documentation to describe build-specific behavior and legitimate dangling dependency cases.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
UnityDataTool.Tests/UnityDataToolPlayerDataTests.cs Adds regression test ensuring preload_dependencies.object never equals -1 and always resolves to an objects row in Player builds.
UnityDataTool.Tests/AnalyzeSceneBundleTests.cs Adds test covering synthetic Scene object creation, non-dangling assetbundle_assets, and presence of scene dependencies in views.
Documentation/analyzer.md Updates docs for assetbundle_asset_view / preload_dependencies* with build-specific semantics and dangling-id explanation.
Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs Resolves synthetic scene id for SBP .sharedAssets files to attach scene-related dependencies consistently.
Analyzer/SQLite/Handlers/PreloadDataHandler.cs Uses PreloadData object id as the dependency “object” when ctx.SceneId is not available (Player builds).
Analyzer/SQLite/Handlers/AssetBundleHandler.cs Creates synthetic Scene objects for SBP/Addressables scene bundles using m_SceneHashes.
Analyzer/SerializedObjects/AssetBundle.cs Parses m_SceneHashes into SceneToFile mapping for SBP/Addressables scene bundles.
Analyzer/Resources/AssetBundle.sql Updates schema comments to reflect corrected Player vs scene-bundle behavior for preload dependencies.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +97 to +109
if (m_InsertedSceneObjects.Add(objId))
{
m_InsertSceneObjectCommand.Transaction = ctx.Transaction;
m_InsertSceneObjectCommand.Parameters["@id"].Value = objId;
m_InsertSceneObjectCommand.Parameters["@serialized_file"].Value = sceneFileId;
m_InsertSceneObjectCommand.Parameters["@name"].Value = asset.Name;
m_InsertSceneObjectCommand.ExecuteNonQuery();

m_InsertCommand.Transaction = ctx.Transaction;
m_InsertCommand.Parameters["@object"].Value = objId;
m_InsertCommand.Parameters["@name"].Value = asset.Name;
m_InsertCommand.ExecuteNonQuery();
}
Comment thread Analyzer/SQLite/Writers/SerializedFileSQLiteWriter.cs
Comment thread Analyzer/SQLite/Handlers/AssetBundleHandler.cs
Add Documentation/assetbundle-format.md, a technical, hands-on companion to the
Unity content overview that covers the AssetBundle object (m_Container,
m_PreloadTable, m_Dependencies), asset preload, and how scenes are laid out
inside a bundle (paired SerializedFiles, PreloadData, and m_SceneHashes for SBP
vs the BuildPlayer- naming convention for BuildPipeline.BuildAssetBundles).
Linked from unity-content-format.md.
@SkowronskiAndrew SkowronskiAndrew marked this pull request as ready for review July 6, 2026 13:34
- AssetBundleHandler: only the synthetic Scene object insert is deduped; the
  assetbundle_assets container row is always written, so a scene exposed by more
  than one bundle still gets its row.
- Normalize all SerializedFile-name keys with ToLowerInvariant instead of
  ToLower so the derived ids are stable across locales (e.g. Turkish-I).
@SkowronskiAndrew

Copy link
Copy Markdown
Collaborator Author

Addressed the Copilot review comments in 7540a24:

  • Scene assetbundle_assets gated by dedup — decoupled: only the synthetic Scene object insert is deduped (objects.id is a PK); the container row is now always written, so a scene exposed by more than one bundle keeps its assetbundle_assets row.
  • ToLower() culture sensitivity — switched to ToLowerInvariant(). Applied to all four SerializedFile-name key sites (not just the two flagged), since they share one key space and mixing the two would risk a key mismatch on locales like Turkish.

Re-verified on a large Addressables build (0 dangling .unity scene rows, 261 scenes resolving with dependencies) and full test suite green (236 + 62).

@SkowronskiAndrew SkowronskiAndrew merged commit 07a7774 into main Jul 6, 2026
5 checks passed
@SkowronskiAndrew SkowronskiAndrew deleted the issue81-fix-preload-dependencies branch July 6, 2026 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

analyze: scene/preload dependencies broken outside BuildPipeline.BuildAssetBundles (dangling assets rows; object -1 rows)

2 participants