Skip to content

Game.Serialization.OwnedVehicleSystem

Assembly: Assembly-CSharp
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
OwnedVehicleSystem is an ECS system used to populate each owner's OwnedVehicle buffer with the vehicles that belong to them. It queries entities that have both a Vehicle marker and an Owner component, and schedules a Burst-compiled IJobChunk (OwnedVehicleJob) that iterates chunks of those entities, reads the Owner component, and appends an OwnedVehicle entry (wrapping the vehicle Entity) into the owner's OwnedVehicle buffer via a BufferLookup. The system uses a generated TypeHandle helper to cache Entity/Component/Buffer handles and has compiler-related wiring (OnCreateForCompiler / __AssignQueries) to set up those handles.


Fields

  • private Unity.Entities.EntityQuery m_Query
    Used to select entities that represent vehicles with an Owner component. This query is created in OnCreate with GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly()) and required for update via RequireForUpdate. It is passed to JobChunk scheduling in OnUpdate.

  • private TypeHandle __TypeHandle
    Compiler-generated helper struct instance that holds the cached type handles required by the job:

  • EntityTypeHandle
  • ComponentTypeHandle (read-only)
  • BufferLookup (read/write)
    The TypeHandle provides the __AssignHandles(ref SystemState) method used to initialize those handles from the system state (called from OnCreateForCompiler).

Properties

  • None.
    This system does not expose public properties.

Constructors

  • public OwnedVehicleSystem()
    Parameterless constructor marked with [Preserve] in the source. Typical default constructor for ECS systems; no custom initialization beyond what OnCreate performs.

Methods

  • protected override void OnCreate()
    Initializes the system query (m_Query) to select Vehicle + Owner entities and calls RequireForUpdate(m_Query) so the system only runs when matching entities exist. Also calls base.OnCreate().

  • protected override void OnUpdate()
    Builds an OwnedVehicleJob instance by obtaining the EntityTypeHandle, ComponentTypeHandle, and BufferLookup from the compiler-generated TypeHandle using InternalCompilerInterface helpers and base.CheckedStateRef. Schedules the job over m_Query using JobChunkExtensions.Schedule and assigns the resulting JobHandle into base.Dependency.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated stub used to set up any EntityQueryBuilder usage at compile-time. In the provided code it constructs and disposes an EntityQueryBuilder(Allocator.Temp) (likely a placeholder produced by the source generator).

  • protected override void OnCreateForCompiler()
    Called by generated code paths to wire up compiler-time initialization: calls __AssignQueries and __TypeHandle.__AssignHandles to populate the TypeHandle from the SystemState, then calls base.OnCreateForCompiler().

  • (Nested) private struct OwnedVehicleJob : IJobChunk
    BurstCompiled job that executes per chunk:

  • Reads the chunk entity array and Owner component array.
  • For each element in the chunk, gets the owner entity from the Owner component and attempts to obtain the owner's OwnedVehicle buffer via BufferLookup.TryGetBuffer.
  • If the buffer exists, appends a new OwnedVehicle wrapping the vehicle Entity. This job implements Execute(in ArchetypeChunk, int, bool, in v128) and forwards the explicit interface call to that implementation.

  • (Nested) private struct TypeHandle
    Holds the three type handles used by the job and exposes __AssignHandles(ref SystemState state) to initialize them:

  • EntityTypeHandle __Unity_Entities_Entity_TypeHandle
  • ComponentTypeHandle __Game_Common_Owner_RO_ComponentTypeHandle
  • BufferLookup __Game_Vehicles_OwnedVehicle_RW_BufferLookup

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Query for all vehicle entities that have an Owner component.
    m_Query = GetEntityQuery(ComponentType.ReadOnly<Vehicle>(), ComponentType.ReadOnly<Owner>());
    // Only run this system when there are matching entities.
    RequireForUpdate(m_Query);
}

[Preserve]
protected override void OnUpdate()
{
    // The actual job scheduling is handled in the system (shown in original source).
    // This demonstrates that the system schedules a Burst IJobChunk that appends
    // OwnedVehicle entries into each owner's buffer for each vehicle entity.
}

Notes and implementation details: - The OwnedVehicleJob is Burst-compiled and uses chunk-based iteration for performance. - The job uses BufferLookup.TryGetBuffer(ownerEntity, out buffer) — if the owner's buffer does not exist, no OwnedVehicle is added for that owner. - The system relies on generated/compiled helpers (InternalCompilerInterface and TypeHandle) to obtain safe handle references via base.CheckedStateRef; this is typical for source-generated ECS systems to ensure correct handle lifetimes and safety.