Skip to content

Game.Serialization.GuestVehicleSystem

Assembly: Game
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
GuestVehicleSystem is an ECS system that collects vehicle entities (DeliveryTruck) that reference a target entity via a Target component and appends each vehicle as a GuestVehicle entry into the target entity's GuestVehicle buffer. The system runs as a job (IJobChunk) to iterate matching chunks and perform buffer writes. It is used during serialization/processing of guest vehicles so targets can know which vehicles are currently visiting them.


Fields

  • private EntityQuery m_Query
    Used to select entities that have DeliveryTruck and Target components. The query is created in OnCreate and required for the system to run (RequireForUpdate).

  • private TypeHandle __TypeHandle
    Holds compiled type handles used by the scheduled job: EntityTypeHandle, ComponentTypeHandle (read-only), and BufferLookup (read/write). Populated via __AssignHandles in OnCreateForCompiler.

Properties

  • (none)

Constructors

  • public GuestVehicleSystem()
    Default constructor. Marked with [Preserve] in the source; no custom initialization beyond the base constructor.

Methods

  • protected override void OnCreate()
    Creates the EntityQuery filtering for DeliveryTruck and Target (both read-only) and calls RequireForUpdate(m_Query) so the system only updates when matching entities exist.

  • protected override void OnUpdate()
    Builds a GuestVehicleJob with the EntityTypeHandle, Target ComponentTypeHandle, and BufferLookup retrieved via InternalCompilerInterface and the stored __TypeHandle. Schedules the job with JobChunkExtensions.Schedule and attaches it to base.Dependency.

  • protected override void OnCreateForCompiler()
    Called by generated/compiled code paths: calls __AssignQueries and assigns the type handles via __TypeHandle.__AssignHandles(ref state). Ensures the system's internal structures are prepared for execution.

  • private void __AssignQueries(ref SystemState state)
    Currently creates and immediately disposes an EntityQueryBuilder(Allocator.Temp). Present for generated-compiler wiring; no persistent queries are constructed here beyond m_Query in OnCreate.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns the following handles from the SystemState:

  • EntityTypeHandle (Entity)
  • ComponentTypeHandle (read-only)
  • BufferLookup (read/write)

  • Nested: [BurstCompile] private struct GuestVehicleJob : IJobChunk

  • Fields:
    • [ReadOnly] public EntityTypeHandle m_EntityType
    • [ReadOnly] public ComponentTypeHandle<Target> m_TargetType
    • public BufferLookup<GuestVehicle> m_GuestVehicles
  • public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    For each entity in the chunk:
    • Read the Entity and its Target component.
    • If the target entity has a GuestVehicle buffer via m_GuestVehicles.HasBuffer(target.m_Target), append a new GuestVehicle constructed with the vehicle entity to that buffer.
  • Implements the IJobChunk.Execute interface method to call the concrete Execute above.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Create a query for DeliveryTruck entities that have a Target component.
    m_Query = GetEntityQuery(ComponentType.ReadOnly<DeliveryTruck>(), ComponentType.ReadOnly<Target>());
    RequireForUpdate(m_Query);
}

[Preserve]
protected override void OnUpdate()
{
    var jobData = new GuestVehicleJob
    {
        m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle, ref base.CheckedStateRef),
        m_TargetType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Common_Target_RO_ComponentTypeHandle, ref base.CheckedStateRef),
        m_GuestVehicles = InternalCompilerInterface.GetBufferLookup(ref __TypeHandle.__Game_Vehicles_GuestVehicle_RW_BufferLookup, ref base.CheckedStateRef)
    };
    base.Dependency = JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency);
}

Notes and tips: - The job uses BufferLookup to append to target buffers; ensure target entities actually have a dynamic buffer of GuestVehicle or HasBuffer will return false. - The GuestVehicleJob is Burst-compiled for performance. The job uses component and entity type handles fetched via the system's TypeHandle to avoid repeated reflection lookups at runtime. - This system is intended to be lightweight: it only runs when there are DeliveryTruck entities with Target components (RequireForUpdate).