Game.Serialization.SpawnLocationElementSystem
Assembly: Game
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
SpawnLocationElementSystem is a Unity ECS system used in Cities: Skylines 2 modding to collect entities that represent spawn/hangaround/parking locations and register them on their owning entities' SpawnLocationElement dynamic buffers. The system finds all entities that have an Owner component and at least one of the marker/location components (SpawnLocation, HangaroundLocation, ParkingLane). For each such location entity it appends a SpawnLocationElement (entity + SpawnLocationType) to the owner's buffer and then walks the owner chain (via Owner components) to add the same entry to every ancestor owner. The work is performed in a Burst-compiled IJobChunk (SpawnLocationElementJob) for performance.
Fields
-
private EntityQuery m_Query
Holds the EntityQuery used to find entities that have an Owner and any of the three location components (SpawnLocation, HangaroundLocation, ParkingLane). The query is created in OnCreate and the system is set to RequireForUpdate(m_Query). -
private TypeHandle __TypeHandle
A private struct instance used to cache type/lookup handles required by the job. __TypeHandle.__AssignHandles(...) initializes the EntityTypeHandle, ComponentTypeHandles (Owner, SpawnLocation, HangaroundLocation, ParkingLane), ComponentLookup, and BufferLookup .
Properties
- This system exposes no public properties.
Constructors
public SpawnLocationElementSystem()
Default constructor. The class is created by the framework; initialization work is performed in OnCreate / OnCreateForCompiler.
Methods
-
protected override void OnCreate()
Creates the EntityQuery that selects entities with a read-only Owner component and any of the three location marker components (SpawnLocation, HangaroundLocation, ParkingLane). Calls RequireForUpdate(m_Query) so the system runs only when matching entities exist. -
protected override void OnUpdate()
Builds an instance of the Burst-compiled SpawnLocationElementJob, filling its EntityTypeHandle, component type handles and lookups from the cached __TypeHandle via InternalCompilerInterface.Get* calls. Schedules the job using JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the returned JobHandle to base.Dependency. -
protected override void OnCreateForCompiler()
Called by the generated/compiled code path; it calls __AssignQueries and __TypeHandle.__AssignHandles to make sure the cached handles and queries are prepared for the compiler-managed execution environment. -
private void __AssignQueries(ref SystemState state)
Internal helper invoked during compiler initialization. In this class it creates/initializes any queries required for the system (the implementation shows an EntityQueryBuilder disposal placeholder).
Nested / Job methods (important behavior summary):
- SpawnLocationElementJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
This is the job body executed per chunk. It: - Reads the native arrays for Entity and Owner from the chunk.
- Determines which kind of location the chunk contains by checking for SpawnLocation, HangaroundLocation, or ParkingLane components and maps that to a SpawnLocationType enum (SpawnLocation, HangaroundLocation, ParkingLane, or None).
- For each entity in the chunk:
- Attempts to get the SpawnLocationElement buffer on owner.m_Owner and appends a SpawnLocationElement(spawnLocationEntity, type) if available.
- Repeatedly follows owner links using m_OwnerData.TryGetComponent(owner.m_Owner, out componentData) to walk the owner chain and append the same SpawnLocationElement to each ancestor owner's buffer, if present.
-
The job is Burst compiled and implements IJobChunk.
-
TypeHandle.__AssignHandles(ref SystemState state)
Initializes all required type handles and lookups from the provided SystemState: EntityTypeHandle, ComponentTypeHandles for Owner/SpawnLocation/HangaroundLocation/ParkingLane, ComponentLookupand BufferLookup .
Notes / Behavior details:
- The job uses BufferLookup
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The real system builds a query similar to this:
m_Query = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { ComponentType.ReadOnly<Owner>() },
Any = new ComponentType[]
{
ComponentType.ReadOnly<SpawnLocation>(),
ComponentType.ReadOnly<HangaroundLocation>(),
ComponentType.ReadOnly<ParkingLane>()
}
});
RequireForUpdate(m_Query);
}
If you need to extend or debug the behavior: - Ensure target owner entities have a dynamic buffer of SpawnLocationElement to receive entries. - The Owner component should contain an Entity reference (owner.m_Owner) that may point to another Owner, forming a chain. - You can inspect scheduled jobs/dependencies via the system's base.Dependency JobHandle if debugging multithreaded behavior.