t1k:unity:dots-core:subscene
| Field | Value |
|---|---|
| Module | dots-core |
| Version | 2.3.2 |
| Effort | high |
| Tools | — |
Keywords: baking, DOTS, scene management, subscene
How to invoke
Section titled “How to invoke”/t1k:unity:dots-core:subsceneDOTS SubScene Baking
Section titled “DOTS SubScene Baking”Handles SubScene authoring → baking → runtime entity loading patterns.
Does NOT handle general ECS patterns (→ dots-ecs) or architecture decisions (→ dots-architecture).
SubScene Lifecycle
Section titled “SubScene Lifecycle”Authoring (MonoBehaviour) → Baker → BlobAsset/Entity → EntityScene (.entities file)- Add
SubScenecomponent to a GameObject in the Editor scene - Unity bakes GameObjects inside to entities on save / domain reload
- At runtime,
SceneSystem.LoadSceneAsyncloads the.entitiesbinary
Baker Patterns
Section titled “Baker Patterns”class MyBaker : Baker<MyAuthoring>{ public override void Bake(MyAuthoring authoring) { var entity = GetEntity(TransformUsageFlags.Dynamic); AddComponent(entity, new MyComponent { Value = authoring.value }); // Declare dependency so baker re-runs when referenced asset changes: DependsOn(authoring.referencedAsset); }}GetEntity flags:
TransformUsageFlags.Dynamic— entity has LocalTransform, needs per-frame updatesTransformUsageFlags.Renderable— entity renders but doesn’t moveTransformUsageFlags.None— pure data entity, no transform overhead
DependsOn(obj) — re-bake when obj changes (prefabs, ScriptableObjects, textures).
LiveConversion vs Full Bake
Section titled “LiveConversion vs Full Bake”| Mode | When | Tradeoff |
|---|---|---|
| LiveConversion | Editor Play Mode | Fast iteration; some fidelity gaps |
| Full bake | Build / asset import | Accurate; slower |
LiveConversion only processes dirty objects — don’t assume full re-bake on every change.
Hybrid Objects (Non-Baking)
Section titled “Hybrid Objects (Non-Baking)”MonoBehaviours that must stay managed (physics callbacks, third-party SDKs):
- Add a
CompanionLinkcomponent via baker - Unity keeps the GameObject alive and syncs its transform from entity
- Never add both an ECS component and a managed component for the same data
Entity Scene Loading
Section titled “Entity Scene Loading”// Async loadvar sceneEntity = SceneSystem.LoadSceneAsync(state.WorldUnmanaged, new Unity.Entities.Hash128(sceneGUID));
// Check loadedbool ready = SceneSystem.IsSceneLoaded(state.WorldUnmanaged, sceneEntity);
// Section loading (large worlds)SceneSystem.LoadSceneAsync(state.WorldUnmanaged, guid, new SceneSystem.LoadParameters { AutoLoad = false });// Then manually load sections by indexGotchas
Section titled “Gotchas”- Stale cache: after changing a Baker, delete
Library/EntityScenesand reimport to force full rebake - Baking order: Bakers run in undefined order — never read another entity’s component inside a Baker; use
GetEntityreferences only - Shared components during baking:
ISharedComponentDatavalues affect chunk assignment at bake time; changing them post-bake causes chunk moves - Transform flattening: deep GameObject hierarchies become flat entity lists — parent-child transform relationships are baked into
LocalTransformoffsets, not preserved as ECS hierarchy unlessTransformUsageFlags.Dynamicis set withWithDynamicUsage - BlobAssetReference: must be created via
BlobBuilderinside Baker; not valid to create at runtime outside a Baker Library/EntityScenes/is empty under Unity 6 — bakes live inLibrary/Artifacts/(2026-05-23). The legacy advice “deleteLibrary/EntityScenesto force rebake” still works for triggering a re-import, but do NOT use the directory’s emptiness as a signal that “no bake happened”. Unity 6 stores baked entity-scene artifacts inLibrary/Artifacts/<2-char-prefix>/<full-hash>plus the binaryLibrary/ArtifactDB. The authoritative bake-success signal inLogs/AssetImportWorker*.logis the line-> (artifact id: '<hash>') in N seconds— a missing/zero-byte EntityScenes dir is normal in Unity 6 + Entities 1.4.- Stale baker exceptions in worker logs mask the current bake state (2026-05-23). When debugging a SubScene that fails to spawn entities, grepping the worker log for
InvalidOperationExceptionorRequired prefabmatches BOTH today’s failure AND every prior failed bake going back to the log’s creation. Always pivot fromgrepto a line-number-anchoredsed -n 'N,Mp'covering only the latestStart importing Assets/SceneDependencyCache/<guid>...block for the SubScene of interest. The latest block’s contents (presence/absence of exceptions, the closingartifact id:line) is the only signal of current state. Assets/SceneDependencyCache/*.sceneWithBuildSettingsmust be gitignored (2026-05-23). Every SubScene bake writes one<guid>.sceneWithBuildSettingsfile (and its.meta) intoAssets/SceneDependencyCache/. These are bake-output artifacts that regenerate on every Play-mode entry — they have no source-of-truth value and will appear as untracked spam on every clone. The stock Unity.gitignoretemplate does NOT cover them. Add the following lines to every Unity DOTS project’s.gitignore(alongside the standard “Packed Addressables” entry):Test: after enter-then-exit Play mode,# SubScene bake artifacts — regenerated on every bake/[Aa]ssets/[Ss]ceneDependencyCache/*.sceneWithBuildSettings/[Aa]ssets/[Ss]ceneDependencyCache/*.sceneWithBuildSettings.metagit status --shortshould NOT show any newSceneDependencyCache/entries. If it does, the gitignore lines above are missing or mis-cased on a non-case-insensitive filesystem.- SubScene bake exceptions are invisible in the Play console — check the AssetImportWorker log (2026-05-29). SubScene baking runs in an AssetImportWorker process, NOT the main editor. A baker throwing during bake (e.g.
AssetReferenceBakerExtensions.ResolveBakedEntityRequiredon an unassigned/empty-GUIDAssetReferenceGameObject) aborts the ENTIRE SubScene bake, producing a silent 0-entity or partial-entity result with NO error in the runtime Play console — the exception is written toLogs/AssetImportWorker*.loginstead. Diagnosis: when a SubScene bakes too few entities,grep -nE "InvalidOperationException|AssetReferenceBaker|<BakerName>" Logs/AssetImportWorker*.log— the stack trace names the exact baker + authoring (e.g.DOTSCombat.ArrowPrefabBaker.Bake at ArrowPrefabAuthoring.cs:37). One unwired AssetReference on one authoring can zero out an entire demo’s spawn. Real incident: BattleDemoSideView spawned 0 units because an empty-GUID arrow AssetReference aborted the bake; no console error; a debugger stalled twice (149K/178K tokens) chasing it via the Play console before the worker log revealed it. (See bullets above for narrowing to the latest bake block via line-anchoredsed.)
Reference Files
Section titled “Reference Files”| Cross-Reference | Content |
|---|---|
→ See dots-ecs | General baking pipeline, IComponentData, SystemAPI |
→ See dots-architecture | When to use SubScene vs runtime spawning |