Game.BatchDataSystem
Assembly: Assembly-CSharp (game)
Namespace: Game.Rendering
Type: class
Base: GameSystemBase, IPostDeserialize
Summary:
BatchDataSystem is the rendering system responsible for updating per-instance rendering data for objects, nets, lanes and zones prior to the GPU culling/rendering stage. It gathers pre-culling results and writes transforms, LOD/fade information and many per-instance properties (colors, wetness, building state, curve matrices, flow, etc.) into the native batch instance store. The system schedules two Burst jobs: BatchDataJob (collects and writes per-entity properties) and BatchLodJob (LOD selection, fade, batch priorities and VT requests). It also coordinates smoothing of interpolated properties and triggers global rendering updates (SH coefficients, LOD parameters).
Fields
-
private RenderingSystem m_RenderingSystem
This holds a reference to the central rendering system used to read rendering-related global state (frame LOD, frameDelta, debug flags, etc.). -
private CameraUpdateSystem m_CameraUpdateSystem
Used to obtain camera parameters and viewer orientation required to compute LOD and pixel-size factors. -
private BatchManagerSystem m_BatchManagerSystem
Reference to the batch manager that owns the NativeBatchGroups and NativeBatchInstances used to store per-group and per-instance data. -
private BatchMeshSystem m_BatchMeshSystem
Used to obtain mesh loading state & priorities and to update mesh-related data. -
private ManagedBatchSystem m_ManagedBatchSystem
Used to collect VT (virtual texture) request max pixel values. -
private PreCullingSystem m_PreCullingSystem
Source of PreCullingData that determines which entities are near camera / need updates. -
private LightingSystem m_LightingSystem
Used to compute light-related factors that influence building-state and other lighting-sensitive properties. -
private MeshColorSystem m_MeshColorSystem
Tracks when mesh colors have changed and when smooth color updates are required. -
private SimulationSystem m_SimulationSystem
Used to read current simulation frame index (used for throttled updates). -
private CitizenPresenceSystem m_CitizenPresenceSystem
Used to detect citizen presence version changes (affects building state). -
private TreeGrowthSystem m_TreeGrowthSystem
Used to detect tree growth updates (can force transform updates for trees). -
private WindSystem m_WindSystem
Provides wind data used for hanging-lane calculations. -
private WetnessSystem m_WetnessSystem
Used to detect changes to surface wetness. -
private DirtynessSystem m_DirtynessSystem
Used to detect surface damage/dirtyness updates. -
private ToolSystem m_ToolSystem
Provides information about active infoview/tool states and editor mode. -
private EntityQuery m_RenderingSettingsQuery
EntityQuery used to fetch current RenderingSettingsData singleton. -
private NativeAccumulator<SmoothingNeeded> m_SmoothingNeeded
Accumulator used by jobs to report that smoothing updates are still needed for some properties (color masks, wetness, damage, etc.). -
private int m_SHCoefficients
Shader property id for setting ambient SH coefficients globally. -
private int m_LodParameters
Shader property id for LOD parameters. -
private bool m_UpdateAll
Flag set by InstancePropertiesUpdated() to force a full update of batch properties next frame. -
private float m_LastLightFactor
Cached light factor used to detect lighting changes that require building state updates. -
private float m_LodFadeTimer
Accumulator used to compute discrete lodFade delta increments when LOD crossfade is enabled. -
private float4 m_LastBuildingStateOverride
Cached editor override state to detect changes to building-state override. -
private uint m_LastCitizenPresenceVersion
Cached system version for citizen presence to detect changes. -
private uint m_LastTreeGrowthVersion
Cached version for tree growth. -
private uint m_LastWetnessVersion
Cached version for wetness. -
private uint m_LastDirtynessVersion
Cached version for dirtiness/damage. -
private uint m_LastFireDamageVersion
Cached version for fire damage (tracked but not exposed publicly). -
private uint m_LastWaterDamageVersion
Cached version for water damage. -
private uint m_LastWeatherDamageVersion
Cached version for weather damage. -
private uint m_LastLaneConditionFrame
Frame index for last lane-condition update check. -
private uint m_LastDamagedFrame
Frame index for last damaged frame check. -
private TypeHandle __TypeHandle
Internal struct that stores ComponentLookup/BufferLookup handles assigned at creation; used to create correct ComponentLookup instances for jobs.
Properties
- No public properties. The system exposes behavior via methods and jobs rather than public properties.
Constructors
public BatchDataSystem()
Default constructor. The system is created by the DOTS world and further initialized in OnCreate() where required subsystem references and resources (like m_SmoothingNeeded accumulator) are created.
Methods
-
protected override void OnCreate()
Initializes subsystem references (RenderingSystem, CameraUpdateSystem, BatchManagerSystem, etc.), prepares queries, creates the NativeAccumulator for smoothing, and stores shader property IDs. Called by the framework when the system is created. -
protected override void OnDestroy()
Disposes m_SmoothingNeeded and performs cleanup. -
public void InstancePropertiesUpdated()
Marks m_UpdateAll true so that a full property update is forced on the next frame (useful when instance-level properties were modified by code and you need the renderer to refresh all instance data). -
public void PostDeserialize(Context context)
Implements IPostDeserialize. Resets internal frame tracking fields (e.g., sets last lane condition / damaged frame to current simulation frame) after deserialization. -
public float GetLevelOfDetail(float levelOfDetail, IGameCameraController cameraController)
Adjusts the requested LOD according to camera controller zoom (if provided). Returns the modified LOD value used when computing LOD parameters. -
protected override void OnUpdate()
Main per-frame update. Collects camera/LOD parameters, updates shader LOD globals, updates meshes, retrieves NativeBatchGroups/Instances, computes culling flags & update masks, schedules BatchDataJob and BatchLodJob, and wires up job dependencies to other systems (BatchMesh, ManagedBatch, PreCulling, Wind, etc.). Also updates global values (SH coefficients). -
private void GetDataQuery(out PreCullingFlags cullingFlags, out UpdateMasks updateMasks)
Determines which PreCullingFlags and UpdateMasks should be used for the current frame based on accumulated changes across subsystems (mesh color smoothing, wetness, tree growth, citizen presence, lane conditions, etc.). It also consumes m_SmoothingNeeded results and resets the accumulator. -
private float CalculateLightFactor()
Reads lighting state from m_LightingSystem and returns a normalized "light factor" value used when computing building-state (how bright/dark it is). -
private void UpdateGlobalValues(NativeBatchInstances<CullingData, GroupData, BatchData, InstanceData> nativeBatchInstances)
Sets global per-frame shader values in the native batch instance store (for example SHCoefficients from RenderSettings.ambientProbe). -
private void __AssignQueries(ref SystemState state)
Internal helper used in generated compiler initialization — sets up any required entity queries (empty in this compiled excerpt). -
protected override void OnCreateForCompiler()
Called by generated code paths; ensures queries and component lookups are assigned for the compiler/IL2CPP path. -
public void PostDeserialize(Context context)
(already listed)
(Implemented as part of IPostDeserialize — see above.)
Nested types (brief):
-
BatchDataJob : IJobParallelForDefer
Burst-compiled job that iterates PreCullingData and writes instance transforms and many per-instance properties for objects, nets, lanes and zones into NativeBatchInstances. Handles smoothing of values, reading many component lookups and buffers (mesh batches, mesh groups, prefab data, animated/skeleton buffers, colors, emissives, lane/curve data, zone cells, etc.). It also accumulates which smoothing types need further smoothing via m_SmoothingNeeded. -
BatchLodJob : IJobParallelFor
Burst-compiled job that performs LOD selection/fading and priority/VT-request aggregation per active group. Updates culling bounds and lodFade ranges per instance and writes lod properties for cross-fading. Also computes batch priorities for background mesh loading. -
Several small helper structs & enums: UpdateMask, UpdateMasks, SmoothingNeeded, CellTypes and TypeHandle. These are used by the jobs to decide which properties to update and to pack zone cell types.
Usage Example
// Example: request a full instance property update from another system or mod code
var world = Unity.Entities.World.DefaultGameObjectInjectionWorld;
if (world != null)
{
var batchDataSystem = world.GetExistingSystemManaged<Game.Rendering.BatchDataSystem>()
?? world.GetOrCreateSystemManaged<Game.Rendering.BatchDataSystem>();
// Tell the BatchDataSystem to refresh all instance properties on next update
batchDataSystem.InstancePropertiesUpdated();
}
// Example: query LOD adjustment helper
float lod = 1.0f;
var cameraController = /* IGameCameraController reference if available */;
var adjusted = batchDataSystem.GetLevelOfDetail(lod, cameraController);
Notes / Tips: - This system is tightly coupled with the game's ECS + native batch rendering infrastructure. Modifying instance properties directly should be followed by calling InstancePropertiesUpdated() so changes are propagated promptly. - The heavy work is done in Burst jobs — when debugging, consider disabling Burst or running in the editor with safety checks if you need easier inspection. - The system aggregates many subsystem versions/frames and only updates the properties that need refreshing (via UpdateMasks and PreCullingFlags) to minimize work each frame.