Skip to content

Game.Citizens.MeetingInitializeSystem

Assembly: Game (assembly used by Cities: Skylines 2 mod code; exact assembly name may vary)
Namespace: Game.Citizens

Type: class

Base: GameSystemBase

Summary:
System that initializes newly created CoordinatedMeeting entities by ensuring each attendee entity in the CoordinatedMeetingAttendee buffer receives an AttendingMeeting component that points back to the meeting. This system schedules a Burst-compiled IJobChunk (InitializeMeetingJob) that iterates meeting entities with a CoordinatedMeetingAttendee buffer and a Created tag. If an attendee already has an AttendingMeeting component, that attendee entry is removed from the meeting's buffer. The system uses a ModificationBarrier5 command buffer to safely add components from a job and to provide proper producer job-handling.


Fields

  • private ModificationBarrier5 m_ModificationBarrier5
    This is the barrier system used to create an EntityCommandBuffer for structural changes produced from jobs. The system obtains it in OnCreate and uses it to create the command buffer passed to the job, and to register the job handle as a producer via AddJobHandleForProducer.

  • private EntityQuery m_MeetingQuery
    EntityQuery that selects meetings to process. It is created in OnCreate to match entities with CoordinatedMeeting (ReadOnly), CoordinatedMeetingAttendee buffer (ReadWrite), and Created (ReadOnly). The system calls RequireForUpdate on this query so it only runs when matching entities exist.

  • private TypeHandle __TypeHandle
    A private holder for the type handles used by jobs (EntityTypeHandle, BufferTypeHandle, ComponentLookup). The __AssignHandles method fills these handles from the SystemState; they are accessed through InternalCompilerInterface when creating jobData in OnUpdate.

Properties

  • This system exposes no public properties.
    All relevant job handles and type handles are private and managed internally.

Constructors

  • public MeetingInitializeSystem()
    Default constructor. The system relies on the ECS lifecycle methods (OnCreate/OnUpdate) to initialize internal state and schedule work; no special construction logic beyond the default is required.

Methods

  • protected override void OnCreate()
    Called when the system is created. It retrieves the ModificationBarrier5 system (m_ModificationBarrier5), builds the m_MeetingQuery to find CoordinatedMeeting entities that are Created and have a CoordinatedMeetingAttendee buffer, and calls RequireForUpdate(m_MeetingQuery) to prevent the system from running when there are no matching meetings.

  • protected override void OnUpdate()
    Prepares and schedules the InitializeMeetingJob. It uses InternalCompilerInterface to obtain the EntityTypeHandle, BufferTypeHandle, and ComponentLookup from the cached TypeHandle, creates an EntityCommandBuffer via m_ModificationBarrier5.CreateCommandBuffer(), fills jobData, schedules the job with JobChunkExtensions.Schedule, assigns the resulting job handle to base.Dependency, and registers the job handle with m_ModificationBarrier5.AddJobHandleForProducer to ensure correct synchronization for the command buffer.

  • protected override void OnCreateForCompiler()
    Compiler-time helper called to assign queries and type handles used by generated code. It calls __AssignQueries and __TypeHandle.__AssignHandles with the system state. (Used in generated/IL2CPP build paths; usually not manually called.)

  • private void __AssignQueries(ref SystemState state)
    Internal helper that can initialize EntityQueryBuilder instances. In this implementation the method constructs and disposes an EntityQueryBuilder (placeholder for generated code patterns). The actual queries used are created in OnCreate.

  • (nested) private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns the EntityTypeHandle, BufferTypeHandle, and ComponentLookup from the given SystemState. This method is marked AggressiveInlining for performance.

  • (nested) private struct InitializeMeetingJob : IJobChunk.Execute(...)
    Burst-compiled job that runs over chunks matched by m_MeetingQuery. For each meeting entity in a chunk it:

  • Gets the DynamicBuffer.
  • Iterates attendees in the buffer:
    • If the attendee entity does NOT have an AttendingMeeting component (checked via m_Attendings lookup), it enqueues an AddComponent(AttendingMeeting { m_Meeting = meeting }) call into the EntityCommandBuffer.
    • Else (attendee already attending another meeting) it removes that attendee entry from the buffer via dynamicBuffer.RemoveAt(j) and decrements the loop index to account for the removed element. The job uses:
    • EntityTypeHandle to access chunk entities,
    • BufferTypeHandle for the meeting's attendee buffer,
    • ComponentLookup (read-only) to test if an attendee already has an AttendingMeeting,
    • EntityCommandBuffer for structural changes (add component).

Usage Example

// Example showing how a Meeting entity can be created so MeetingInitializeSystem processes it.
// This is simplified pseudo-usage for a runtime script or another system.

var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create a meeting archetype (CoordinatedMeeting + buffer + Created tag)
Entity meeting = entityManager.CreateEntity();
entityManager.AddComponentData(meeting, new CoordinatedMeeting { /* meeting data */ });
var buffer = entityManager.AddBuffer<CoordinatedMeetingAttendee>(meeting);
entityManager.AddComponentData(meeting, new Created());

// Create attendee entities
Entity attendee1 = entityManager.CreateEntity();
Entity attendee2 = entityManager.CreateEntity();
// (attendee entities may have other components; if an attendee already has AttendingMeeting,
// it will be removed from the meeting's buffer by the job)

// Add attendees to the meeting buffer
buffer.Add(new CoordinatedMeetingAttendee { m_Attendee = attendee1 });
buffer.Add(new CoordinatedMeetingAttendee { m_Attendee = attendee2 });

// On the next frame update, MeetingInitializeSystem's job will:
// - Add AttendingMeeting component to attendee1 and attendee2 if they do not already have it,
// - Remove entries in the meeting buffer for attendees that already had an AttendingMeeting.

Notes and tips: - This system is designed to run only when CoordinatedMeeting entities are created (uses the Created tag and RequireForUpdate). Ensure meetings are created with a Created tag (or the same lifecycle used by the game's entity creation logic) so they are processed. - Because the job removes entries from the meeting's attendee buffer when attendees are already attending another meeting, the result is that only valid, unassigned attendees receive AttendingMeeting components. - The use of ModificationBarrier5 and an ECB ensures structural changes from the job are applied safely and synchronized with the job system.