Skip to content

Game.PassengerSystem

Assembly:
Assembly-CSharp.dll (inferred)

Namespace:
Game.Serialization

Type:
class (CompilerGenerated)

Base:
GameSystemBase

Summary:
PassengerSystem is an ECS system that collects passenger entities and appends them to the passenger buffer on their current vehicle or transport entity. It schedules a Burst-compiled IJobChunk (PassengerJob) that iterates entities having either CurrentVehicle or CurrentTransport components and, using a BufferLookup, writes Passenger entries into the corresponding vehicle/transport entity buffers. The system requires entities that have either CurrentVehicle or CurrentTransport to exist before it runs (RequireForUpdate).


Fields

  • private EntityQuery m_Query
    Holds the query used to find entities that have either CurrentVehicle or CurrentTransport. The query is created in OnCreate and the system's update is gated with RequireForUpdate(m_Query) so the system runs only when matching entities exist.

  • private TypeHandle __TypeHandle
    Container for the entity/component/buffer handles used by the job. __TypeHandle exposes:

  • EntityTypeHandle for Entity
  • ComponentTypeHandle (read-only)
  • ComponentTypeHandle (read-only)
  • BufferLookup (read/write) These handles are assigned via __AssignHandles(ref SystemState).

  • private struct PassengerJob (nested)
    Burst-compiled IJobChunk implementation that performs the core work: reads CurrentVehicle and CurrentTransport components and writes Passenger entries into buffers on vehicle/transport entities via BufferLookup.

  • private struct TypeHandle (nested)
    Struct used to hold and assign entity/component/buffer type handles; the system writes/reads through InternalCompilerInterface using these handles.

Properties

  • (None public on this type)
    The system does not expose public properties; it uses internal TypeHandle fields and schedules jobs by assigning into local jobData in OnUpdate.

Constructors

  • public PassengerSystem()
    Default (compiler-generated) constructor that calls base constructor. The system uses OnCreate to initialize its query and requires update based on that query.

Methods

  • protected override void OnCreate()
    Creates the EntityQuery that matches entities with either CurrentVehicle or CurrentTransport:
  • Any = ComponentType.ReadOnly(), ComponentType.ReadOnly() Calls RequireForUpdate(m_Query) so the system will only run when there are matching entities.

  • protected override void OnUpdate()
    Builds a PassengerJob instance and sets its handles from the TypeHandle via InternalCompilerInterface:

  • m_EntityType (EntityTypeHandle)
  • m_CurrentVehicleType (ComponentTypeHandle, read-only)
  • m_CurrentTransportType (ComponentTypeHandle, read-only)
  • m_Passengers (BufferLookup, read/write) Schedules the job with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the resulting JobHandle to base.Dependency.

  • protected override void OnCreateForCompiler()
    Compiler-time helper used to assign handles and queries when the system is compiled/generated; calls __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state)
    Generated method that in this file currently constructs and disposes an EntityQueryBuilder(Allocator.Temp). Present for compiler bookkeeping; real query initialization happens in OnCreate.

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

  • state.GetEntityTypeHandle()
  • state.GetComponentTypeHandle(isReadOnly: true)
  • state.GetComponentTypeHandle(isReadOnly: true)
  • state.GetBufferLookup()

  • private struct PassengerJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Job execution:

  • Retrieves entity array and arrays of CurrentVehicle and CurrentTransport for the chunk.
  • Iterates CurrentVehicle array; for each entry, checks m_Passengers.HasBuffer(currentVehicle.m_Vehicle) and if present, adds Passenger(passengerEntity) to that buffer.
  • Iterates CurrentTransport array similarly, adding Passenger entries to the buffer on currentTransport.m_CurrentTransport if the buffer exists. Notes:
  • Both CurrentVehicle and CurrentTransport are read-only in the job.
  • BufferLookup is used to add entries to vehicle buffers (RW).
  • The job is Burst-compiled for performance and runs as a chunk job.

  • void IJobChunk.Execute(...)
    Explicit interface implementation that forwards to the job's Execute method.

Usage Example

This system is registered in the ECS world automatically as a GameSystemBase-derived system. It expects vehicle/transport entities to have a dynamic buffer of type Passenger, and passenger entities to have either CurrentVehicle or CurrentTransport pointing to that vehicle/transport entity.

Example: ensure a vehicle entity has a Passenger buffer and show how a separate system might add a passenger to a vehicle buffer (PassengerSystem will also add them based on CurrentVehicle/CurrentTransport):

// Ensure vehicle entity has a Passenger buffer (e.g., at creation time)
EntityManager.AddBuffer<Passenger>(vehicleEntity);

// Example system that sets a passenger's CurrentVehicle to cause PassengerSystem to add it.
[Preserve]
public partial class ExampleAssignPassengerSystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entity vehicleEntity = /* get or create vehicle entity */;
        Entity passengerEntity = /* passenger entity */;

        // Add or set a CurrentVehicle component on passengerEntity so PassengerSystem will process it
        if (!EntityManager.HasComponent<CurrentVehicle>(passengerEntity))
        {
            EntityManager.AddComponentData(passengerEntity, new CurrentVehicle { m_Vehicle = vehicleEntity });
        }
        else
        {
            EntityManager.SetComponentData(passengerEntity, new CurrentVehicle { m_Vehicle = vehicleEntity });
        }

        // PassengerSystem (on its next update) will pick up passengers with CurrentVehicle
        // and append Passenger(passengerEntity) into the vehicle's Passenger buffer.
    }
}

Notes and caveats: - The job relies on BufferLookup.HasBuffer before calling the buffer indexer. If the vehicle/transport entity does not have a Passenger buffer, no write is attempted. - CurrentVehicle and CurrentTransport are treated as mutually independent: if an entity had both (unlikely), it would be attempted for both loops. The EntityQuery is built with Any so an entity with either component will be included. - The job is Burst-compiled and scheduled with JobChunkExtensions.Schedule, so buffer writes happen concurrently across chunks; BufferLookup provides thread-safe access patterns expected by ECS for appending to dynamic buffers.