Game.Serialization.LifepathEntrySystem
Assembly:
Assembly-CSharp (game managed assembly; typical for Cities: Skylines 2 mods)
Namespace:
Game.Serialization
Type:
class
Base:
GameSystemBase
Summary:
System responsible for repairing/ensuring consistency of lifepath (LifePathEntry) references created by Chirp entities during deserialization. It scans Chirp entities and makes sure the Chirp sender entity has a LifePathEntry buffer that references the chirp. If the sender lacks the buffer, the chirp entity is flagged as Deleted. The system uses a DeserializationBarrier to record structural changes via an EntityCommandBuffer. The actual work is performed by a nested IJobChunk (FixLifepathChirpReferencesJob) scheduled in parallel.
Fields
-
private EntityQuery m_ChirpQuery
Query selecting entities that have a Chirp component and a LifePathEvent marker. Used to drive updates only when relevant data exists. -
private DeserializationBarrier m_DeserializationBarrier
A barrier system used to obtain an EntityCommandBuffer for making structural changes (append to buffers, add components) safely from jobs during deserialization flow. -
private TypeHandle __TypeHandle
Generated container of EntityTypeHandle / ComponentTypeHandle / BufferLookup handles used by the job. Populated by __AssignHandles at compile/runtime as part of the DOTS codegen pattern. -
private struct TypeHandle
A nested helper struct that contains: EntityTypeHandle __Unity_Entities_Entity_TypeHandle
(read-only) — handle to access entity IDs in chunks.ComponentTypeHandle<Chirp> __Game_Triggers_Chirp_RO_ComponentTypeHandle
(read-only) — handle to read Chirp component data.BufferLookup<LifePathEntry> __Game_Triggers_LifePathEntry_RO_BufferLookup
(read-only) — buffer lookup to read LifePathEntry buffers for sender entities.-
void __AssignHandles(ref SystemState state)
— populates the above handles from the provided SystemState; marked AggressiveInlining. -
public struct FixLifepathChirpReferencesJob : IJobChunk
Nested job struct that implements the chunked job to fix lifepath references. Key fields: [ReadOnly] public EntityTypeHandle m_EntityTypeHandle
— to access entities in the chunk.[ReadOnly] public ComponentTypeHandle<Chirp> m_ChirpType
— to read Chirp components.[ReadOnly] public BufferLookup<LifePathEntry> m_EntryDatas
— to lookup LifePathEntry buffers by sender entity.public EntityCommandBuffer.ParallelWriter m_CommandBuffer
— to append entries or add components in parallel.
Behavior (summary):
- For each entity in the chunk:
- Get the Chirp component and its m_Sender entity.
- If the sender has a LifePathEntry buffer and the buffer does not already contain an entry for this chirp, append a LifePathEntry(entity) to the sender's buffer via the command buffer.
- If the sender does not have the buffer, add a Deleted component to the chirp entity via the command buffer.
- Implements the IJobChunk.Execute explicitly and forwards to a typed Execute method.
- Contains a helper Contains(DynamicBuffer
Properties
- (none public)
This system does not expose public properties. All job handles / data are private and managed internally. The nested job uses type handles and buffer lookups injected at OnUpdate.
Constructors
public LifepathEntrySystem()
[Preserve] default constructor. Standard generated/empty constructor for the system.
Methods
[Preserve] protected override void OnCreate()
Initializes the system:- Creates m_ChirpQuery to select entities with Chirp and LifePathEvent.
- Acquires (or creates) the DeserializationBarrier system from the same World.
-
Calls RequireForUpdate(m_ChirpQuery) so the system only runs when matching entities exist.
-
[Preserve] protected override void OnUpdate()
Schedules the FixLifepathChirpReferencesJob: - Fills jobData with EntityTypeHandle, ComponentTypeHandle
, BufferLookup (via InternalCompilerInterface getters and the stored __TypeHandle), and a parallel EntityCommandBuffer from the DeserializationBarrier. - Schedules the job via JobChunkExtensions.ScheduleParallel(jobData, m_ChirpQuery, base.Dependency).
-
Adds the resulting Dependency to the DeserializationBarrier via AddJobHandleForProducer to ensure structural changes execute correctly.
-
protected override void OnCreateForCompiler()
Called by generated code paths to ensure the TypeHandle and queries are assigned for compiled systems: - Calls __AssignQueries(ref CheckedStateRef).
-
Calls __TypeHandle.__AssignHandles(ref CheckedStateRef).
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Generated helper that currently creates and disposes an EntityQueryBuilder(Allocator.Temp) (no extra query assignment logic here in the current codegen output). -
FixLifepathChirpReferencesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Per-chunk execution entry point (also exposed via explicit interface implementation). Retrieves entity and chirp arrays, iterates entries, and uses buffer lookup + command buffer to repair or mark Deleted entities as described above. -
private bool Contains(DynamicBuffer<LifePathEntry> entries, Entity chirp)
Helper method used by the job to determine if a given LifePathEntry buffer already contains an entry for the chirp entity. Performs a linear search over the buffer.
Usage Example
// The system is registered in the World automatically as part of game systems.
// Example: The system's OnCreate sets up the query and barrier; OnUpdate runs the job.
// If you need to interact with it from a mod, you can fetch it from the World:
var world = World.DefaultGameObjectInjectionWorld;
var lifepathSystem = world.GetExistingSystemManaged<Game.Serialization.LifepathEntrySystem>();
// The system runs on its own (RequireForUpdate ensures it only updates when Chirp+LifePathEvent entities exist).
Notes: - This system is intended to run during deserialization flows to repair cross-entity lifepath references created by serialized Chirp entities. - It uses a DeserializationBarrier to perform structural changes from a parallel job safely. - The job does a linear scan of LifePathEntry buffers; if buffer sizes are large consider the cost of this check during large deserialization batches.