[#81] Fix scene/preload dependencies for Player and Scriptable Build Pipeline builds#87
Merged
Merged
Conversation
…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.
Contributor
There was a problem hiding this comment.
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
PreloadDatadependencies attach to thePreloadDataobject 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(); | ||
| } |
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.
- 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).
Collaborator
Author
|
Addressed the Copilot review comments in 7540a24:
Re-verified on a large Addressables build (0 dangling |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #81.
analyzemis-recorded scene/preload dependencies for every build exceptBuildPipeline.BuildAssetBundles. Both symptoms shared one root cause — a synthetic "Scene" object (and a validSceneId) was only created when a SerializedFile was namedBuildPlayer-<SceneName>. This PR fixes both cases.Changes
Player builds (
preload_dependencies.objectwas -1)A player build has no scene object, but it still contains
PreloadDataobjects (one per scene insharedassetsN.assets, plus one inglobalgamemanagers.assets). Their dependencies were all attributed to object id-1.PreloadDataHandlernow attributes the dependencies to thePreloadDataobject 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 theBuildPlayer-regex never matched, so no Scene object was created: theassetbundle_assetsrows for scenes dangled and the scene→dependency relationship was lost.AssetBundle.csnow parses the AssetBundle object'sm_SceneHashes(scene path → scene SerializedFile), guarded for builds that don't emit it.AssetBundleHandlercreates one syntheticSceneobject per scene, keyed on the scene's SerializedFile, plus itsassetbundle_assetsrow.SerializedFileSQLiteWriterresolves the same scene object id for a<file>.sharedAssetsfile, soPreloadDataHandlerand 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_dependenciesbut share the scene object'sserialized_file.Docs / comments
Documentation/analyzer.md: reworked thepreload_dependencies/preload_dependencies_view/assetbundle_asset_viewsections 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).AnalyzeSceneBundleTests(scene resolves, no danglingassetbundle_assets, dependencies present inpreload_dependencies_view) and, from the player-build fix,Analyze_PlayerDataPreloadDependencies_ObjectResolvesToRealObject..unityscene rows → 0, 261 synthetic Scene objects created, and all 261 scenes now show their dependencies inpreload_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.BuildAssetBundlesbundle and the SBP path was verified manually. Adding SBP test data is tracked in #86.