Skip to content

Game.Rendering.ObjectColorSystem

Assembly: Game (Unity/Assembly-CSharp)
Namespace: Game.Rendering

Type: public class ObjectColorSystem

Base: GameSystemBase

Summary:
ObjectColorSystem computes and writes visual "infoview" colors (Game.Objects.Color) for in-game objects (buildings, vehicles, trees, utility objects, transport stops, etc.) based on active info modes and various simulation data. It collects active infoview definitions and schedules several parallel IJobChunk jobs to: - determine which infoview (if any) applies to each object, - compute a color index and intensity/value per object according to the selected infoview and simulation values (crime, pollution, electricity/water flows, damage, fire hazard, mail, wealth, and many others), - propagate colors from parent objects to middle/subobjects and temporary objects, - and handle special cases like sub-building colorization and "subColor" flags for lot coloring/under construction/destroyed states.

The system integrates with other systems (ToolSystem, LocalEffectSystem, ClimateSystem, FireHazardSystem, TelecomCoverageSystem, CitySystem, PrefabSystem) and uses Prefab/component lookups and city-wide parameters (pollution, fire config, telecom coverage, etc.) to compute results efficiently via Burst-compiled jobs.


Fields

  • private EntityQuery m_ObjectQuery
    Description: Query selecting objects that have a Game.Objects.Color component and are eligible to have colors computed (filtering out hidden/deleted and certain owner patterns). Used as the main query for UpdateObjectColorsJob.

  • private EntityQuery m_MiddleObjectQuery
    Description: Query for "middle" objects (e.g., building roots and controlled vehicles) that need a different propagation scheme applied by UpdateMiddleObjectColorsJob.

  • private EntityQuery m_TempObjectQuery
    Description: Query for temporary objects (with the Temp component) whose colors should be copied from their original objects by UpdateTempObjectColorsJob.

  • private EntityQuery m_SubObjectQuery
    Description: Query for sub-objects (children) that receive colors from their owners via UpdateSubObjectColorsJob.

  • private EntityQuery m_InfomodeQuery
    Description: Query that returns active infoview (infomode) prefab components. Used to gather which infoviews are currently active and their priorities/indexes.

  • private EntityQuery m_HappinessParameterQuery
    Description: Query used to ensure happiness parameter data exists before system updates (RequireForUpdate).

  • private EntityQuery m_EconomyParameterQuery
    Description: Query used to ensure economy parameter data exists before system updates.

  • private EntityQuery m_PollutionParameterQuery
    Description: Query used to read pollution parameter singletons used when computing pollution-based colors.

  • private EntityQuery m_FireConfigQuery
    Description: Query used to get current FireConfigurationData prefab entity for fire hazard calculations.

  • private EventHelpers.FireHazardData m_FireHazardData
    Description: Helper data structure used by the system to compute building/tree fire hazard and risk factors; updated before the jobs run.

  • private ToolSystem m_ToolSystem
    Description: Reference to the game's ToolSystem; used to determine whether an infoview is active.

  • private LocalEffectSystem m_LocalEffectSystem
    Description: Used to obtain read data dependency for local effects and to register readers of local effect data when scheduling jobs.

  • private ClimateSystem m_ClimateSystem
    Description: Needed to provide climate parameters (e.g., temperature) when computing fire hazard.

  • private FireHazardSystem m_FireHazardSystem
    Description: Provides fire hazard / no-rain-days used by m_FireHazardData.

  • private TelecomCoverageSystem m_TelecomCoverageSystem
    Description: Provides telecom coverage sampling used for network quality infoviews.

  • private CitySystem m_CitySystem
    Description: Source for the city entity reference.

  • private PrefabSystem m_PrefabSystem
    Description: Used to read prefabs (for example fire configuration prefab).

  • private TypeHandle __TypeHandle
    Description: Internal struct storing ComponentTypeHandle/ComponentLookup/BufferLookup handles used by jobs. Populated on create for compiler-driven scheduling.

Properties

  • None (no public properties exposed by this system).

Constructors

  • public ObjectColorSystem()
    Description: Default constructor. The system is [Preserve] attributed in the source and uses OnCreate to initialize references and EntityQueries.

Methods

  • protected override void OnCreate()
    Description: Initializes system references (ToolSystem, LocalEffectSystem, ClimateSystem, FireHazardSystem, TelecomCoverageSystem, CitySystem, PrefabSystem), constructs several EntityQuery definitions (object, middle-object, temp, sub-object, infomode, and parameter queries), builds the FireHazardData helper and sets RequireForUpdate for parameter queries. Also prepares internal handles via OnCreateForCompiler path.

  • protected override void OnUpdate()
    Description: Main update logic. If an infoview is active and there are objects to process:

  • obtains read dependencies (e.g., local effect read data),
  • collects active infomode chunks into a temporary NativeList,
  • updates FireHazardData with climate and local effect info,
  • prepares and populates job data structs (UpdateObjectColorsJob, UpdateMiddleObjectColorsJob, UpdateTempObjectColorsJob, UpdateSubObjectColorsJob) including handing off many ComponentTypeHandle/ComponentLookup/BufferLookup references via the TypeHandle,
  • schedules the jobs in parallel and sets up proper JobHandle dependencies between them,
  • disposes temporary lists, registers readers with dependent systems, and updates base.Dependency.

The update schedules a Burst-compiled UpdateObjectColorsJob that does the heavy per-chunk color computation.

  • protected override void OnCreateForCompiler()
    Description: Called by the compiled code path to assign queries and component handles for the generated job structs. Internally calls __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state)
    Description: Internal helper used during compiled initialization. In the source it contains a small placeholder call (EntityQueryBuilder disposal) — real query assignments are constructed in OnCreate.

  • Nested job structs (Burst-compiled), each implementing IJobChunk:

  • UpdateObjectColorsJob
    Summary: Core job that iterates chunks of objects and computes Game.Objects.Color values per entity based on active infomodes. It:

    • checks if chunk contains buildings and handles building-specific logic (including sub-building ownership),
    • determines color index from active infoview definitions (building/transport stop/vehicle/object/net status),
    • computes per-entity color value using many helper functions: GetBuildingColor, GetBuildingStatusType/GetBuildingStatusColors, GetTransportStopColor, GetVehicleColor, GetNetStatusColors, GetObjectStatusType/GetObjectStatusColors,
    • writes colors to the Game.Objects.Color native array for that chunk,
    • applies CheckColors that marks subColor and handles lot colorization/under construction/destroyed flags.

    Notable internal helpers (within the job): - GetBuildingColor / HasBuildingColor: find which building-type infoview applies (priority) and whether a chunk matches it. - GetBuildingStatusType / HasBuildingStatus: find building status infoviews and compute their colors (many cases: crime, mail, wealth, education, health, garbage, profitability, electricity/water consumption, pollution sources, lodging, etc.). - GetTransportStopColor / HasTransportStopColor: identify transport stop infoview type (bus, train, ship, etc.). - GetVehicleColor / HasVehicleColor: identify vehicle-type infoviews. - GetObjectStatusType / HasObjectStatus and GetObjectStatusColors: handle object-specific infoviews like wood resources, fire hazard, damage, destroyed, extractor placeholders, tourists. - GetNetStatusColors: computes utility network flow colors based on connected edges and owner connection information (electricity low/high, water pipes, sewage, oil/resource flows). Produces both index and value components.

    The job uses many ComponentLookups/BufferLookups (households, citizens, prefab data, pollution parameters, connected edges, etc.) to compute accurate simulation-driven colors. The job is [BurstCompile]d for performance.

  • UpdateMiddleObjectColorsJob
    Summary: Propagates or fills in colors for "middle" objects. For building chunks it will copy color from owner entities if a middle-object itself has no explicit index and the owner's color is not excluded (excluded indices are determined from object-status infoviews like Damage/Destroyed). For vehicles controlled by a Controller component it copies the controller's color into the controlled entity if appropriate. Also handles clearing color when no controller exists. Runs after UpdateObjectColorsJob to ensure propagation.

  • UpdateTempObjectColorsJob
    Summary: For objects marked Temp, copies color from the original object (Temp.m_Original) into the temporary entity's Game.Objects.Color component.

  • UpdateSubObjectColorsJob
    Summary: Propagates colors to subobjects (children). For trees it has special elevation handling (if tree is off-ground, attempt to use owner's color only if owner has color or propagation rules say so). For generic subobjects, walks the Owner chain until a top-level building/vehicle owner is found and copies that owner's color into the sub-object. Ensures subColor semantics and elevation-based propagation are respected.

  • TypeHandle (private struct)
    Summary: Internal struct that stores all ComponentTypeHandle, BufferTypeHandle, ComponentLookup and BufferLookup instances used by the job structs. It has a __AssignHandles method called during initialization to cache handles for fast job scheduling.

  • void IJobChunk.Execute(...) implementations inside each job struct
    Description: Standard IJobChunk Execute mapping that forwards to the internal Execute method used by each job.

Usage Example

// Get the system instance (World.DefaultGameObjectInjectionWorld used in typical ECS setups)
var objectColorSystem = World.DefaultGameObjectInjectionWorld
    .GetExistingSystemManaged<Game.Rendering.ObjectColorSystem>();

// The system runs automatically during the ECS update loop when an infoview is active.
// You can read the color of an entity using the EntityManager (example):
Game.Objects.Color color = EntityManager.GetComponentData<Game.Objects.Color>(someEntity);

// If you need to inspect active infomodes or debug colors, query entities that have InfomodeActive
var infomodeQuery = objectColorSystem.GetEntityQuery(ComponentType.ReadOnly<InfomodeActive>());
// ...and read their Infoview data as needed.

Notes for modders: - The system writes to the Game.Objects.Color component; changes here control how objects are colorized by rendering/selection visualization. - Colors are encoded as an index (infoview index) and a value/intensity (0–255). The job sets m_SubColor in special cases (lot coloring, under construction/cleared/destroyed) so subobjects can be tinted appropriately. - The system is heavily optimized and uses many internal component lookups — altering component types or infoview prefabs may require careful compatibility checks. - Because the core computation runs in Burst jobs in parallel, direct modification of the component lookups while the jobs run can cause race conditions. Use the ECS job dependency system if you schedule your own jobs that read/write color-related components.