Game.ParkInitializeSystem
Assembly: Game (game code assembly containing simulation systems)
Namespace: Game.Buildings
Type: class
Base: GameSystemBase
Summary:
ParkInitializeSystem is an ECS system responsible for initializing park instances when they are created. It queries for entities that contain a Park component and a PrefabRef (and the Created marker), and schedules a Burst-compiled IJobChunk (InitializeParksJob) to copy data from the park prefab (ParkData and CoverageData) into the instance components. The job sets instance maintenance values and computes modified service coverage using city-wide CityModifier buffers (via ParkAISystem.GetModifiedServiceCoverage). This system depends on the CitySystem to obtain the city entity and its modifiers.
Fields
-
private CitySystem m_CitySystem
Holds a reference to the CitySystem instance in the current World. Used to obtain the city entity (and implicitly access city-wide data such as CityModifier buffers) during job scheduling. -
private EntityQuery m_ParkQuery
An EntityQuery that matches park entities to be initialized. It is created in OnCreate to require entities with Park (ReadWrite), PrefabRef (ReadOnly) and Created marker (ReadOnly) so the system runs only when such entities exist. -
private TypeHandle __TypeHandle
Holds component type handles and lookups used for scheduling jobs. The nested TypeHandle structure caches ComponentTypeHandle, ComponentLookup and BufferLookup instances and assigns them from the SystemState when the system is created for the compiler.
Properties
- (none)
This system does not expose public properties.
Constructors
public ParkInitializeSystem()
Default constructor. The system is constructed by the ECS world; initialization logic occurs in OnCreate.
Methods
-
protected override void OnCreate()
Creates/initializes system state: obtains the CitySystem instance, builds the m_ParkQuery to find newly created park entities (Park + PrefabRef + Created), and calls RequireForUpdate to ensure the system only runs when matching entities exist. -
protected override void OnUpdate()
Schedules the InitializeParksJob in parallel over the m_ParkQuery. It prepares all required ComponentTypeHandle, ComponentLookup and BufferLookup values via InternalCompilerInterface.Get* using the cached __TypeHandle and passes the city Entity from m_CitySystem to the job. The resulting JobHandle is stored back into base.Dependency. -
protected override void OnCreateForCompiler()
Compiler helper: assigns queries and type handles for the ahead-of-time compiled representation. It calls __AssignQueries and __TypeHandle.__AssignHandles with the system state. -
private void __AssignQueries(ref SystemState state)
Compiler-generated placeholder that constructs any required EntityQueryBuilder and disposes it. Present to satisfy generated codepaths; real query assignments are done in OnCreate.
Nested types and their relevant methods:
private struct InitializeParksJob : IJobChunk
Burst-compiled IJobChunk that runs over chunks matched by m_ParkQuery. Main responsibilities:- Read PrefabRef and Park components from the chunk and read/write Park and ModifiedServiceCoverage components.
- For each entity in the chunk, look up its prefab entity and, if the prefab has ParkData, copy the prefab's maintenance pool value into the Park instance (park.m_Maintenance).
- If the prefab has CoverageData, compute and write the ModifiedServiceCoverage using ParkAISystem.GetModifiedServiceCoverage, passing in the instance Park, the prefab ParkData, prefab CoverageData, and the city's CityModifier buffer (if the city entity is valid).
Methods:
- public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
The job's execution entry point; iterates chunk entities and performs initialization as described above.
-
void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Explicit interface implementation that calls the public Execute method. -
private struct TypeHandle
Holds the component type/lookup handles used by the job. Fields include: - ReadOnly ComponentTypeHandle
- ComponentTypeHandle
- ComponentTypeHandle
- ReadOnly ComponentLookup
- ReadOnly ComponentLookup
- ReadOnly BufferLookup
Methods:
- public void __AssignHandles(ref SystemState state)
Assigns the stored handles using state.GetComponentTypeHandle, state.GetComponentLookup and state.GetBufferLookup; used by compiler-generated OnCreateForCompiler wiring.
Usage Example
// The ParkInitializeSystem is an ECS system that runs automatically when parks are created.
// Example: get a reference to the system from a mod and query whether it exists.
var world = Unity.Entities.World.DefaultGameObjectInjectionWorld;
var parkInitSystem = world.GetExistingSystemManaged<Game.Buildings.ParkInitializeSystem>();
if (parkInitSystem != null)
{
// The system will automatically initialize Park components for newly created parks.
// Ensure park prefabs include ParkData and CoverageData components so instances get proper values.
}
Additional notes for modders: - Park initialization depends on prefab components ParkData and CoverageData. If you add custom park prefabs, include those components (or ensure your prefab provides the expected values) for the system to copy maintenance and coverage settings. - City modifiers (CityModifier buffer) are considered when computing modified coverage; changes to city modifiers will affect how park coverage is initialized.