Skip to content

Game.FilterLoadedSystem

Assembly: Assembly-CSharp
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
FilterLoadedSystem is a small ECS system used during New Game loading to migrate or remove Owner components for lane entities that were created in the editor (EditorContainer). When a new game is started and there are EditorContainer entities present, the system iterates net lane entities (Lane + Owner) and for each lane whose Owner references an entity that is an EditorContainer it tries to copy the authoritative Owner component from that owner entity to the lane. If the referenced owner entity does not actually have an Owner component, the lane's Owner component is removed. After processing, all EditorContainer entities are destroyed. The heavy work is done in a Burst-compiled IJobChunk (CheckLanesJob) and applied via an EntityCommandBuffer for thread-safe parallel writes.


Fields

  • private LoadGameSystem m_LoadGameSystem
    Reference to the LoadGameSystem in the same World. Used to check the current load context (Purpose) so this system only runs its logic during NewGame loading.

  • private EntityQuery m_NetLaneQuery
    EntityQuery that selects entities with Lane and Owner components (read-only). Represents the set of lane entities that may need their Owner fixed up.

  • private EntityQuery m_EditorContainerQuery
    EntityQuery that selects entities with EditorContainer component (read-only). Used both as a condition to run the filter and to destroy the editor container marker entities afterwards.

  • private TypeHandle __TypeHandle
    Container holding the EntityTypeHandle/ComponentTypeHandle/ComponentLookup instances required by the job. Populated via __AssignHandles in OnCreateForCompiler.

  • (nested) private struct CheckLanesJob : IJobChunk
    Burst-compiled job that executes per-chunk. It:

  • Reads the chunk Entity array and the Owner component array.
  • Uses ComponentLookup and ComponentLookup to check and fetch components across entities.
  • For entries where the owner entity has an EditorContainer, it tries to fetch the authoritative Owner component data from that owner entity and either sets the Owner component on the lane entity or removes the Owner component if the owner entity lacks it.
  • Applies changes through an EntityCommandBuffer.ParallelWriter for safe parallel modification.

  • (nested) private struct TypeHandle
    Holds internal read-only handles:

  • EntityTypeHandle
  • ComponentTypeHandle (read-only)
  • ComponentLookup (read-only)
  • ComponentLookup (read-only)
    Provides __AssignHandles(ref SystemState state) to initialize those handles from a SystemState.

Properties

  • None (no public properties exposed by this system)

Constructors

  • public FilterLoadedSystem()
    Default parameterless constructor. Marked with [Preserve] in the source so the system is not stripped by linkers.

Methods

  • protected override void OnCreate()
    Called when the system is created. Implementation:
  • Calls base.OnCreate().
  • Acquires the LoadGameSystem instance from the World and stores it to m_LoadGameSystem.
  • Creates the entity queries used by the system:

    • m_NetLaneQuery = query for Lane + Owner (read-only).
    • m_EditorContainerQuery = query for EditorContainer (read-only).
  • protected override void OnUpdate()
    Main runtime logic. Behavior:

  • If LoadGameSystem.context.purpose == Purpose.NewGame AND there is at least one EditorContainer entity:
    • If there are lanes matching m_NetLaneQuery:
    • Create a temporary EntityCommandBuffer.
    • Schedule the Burst-compiled CheckLanesJob in parallel over m_NetLaneQuery. The job uses EntityTypeHandle, ComponentTypeHandle, ComponentLookup, ComponentLookup, and the ECB parallel writer. The scheduled job is immediately .Complete()d.
    • Playback the ECB to apply changes to the EntityManager, and dispose the ECB.
    • Destroy all EditorContainer entities (EntityManager.DestroyEntity(m_EditorContainerQuery)).
  • In short: run owner fix-up only on NewGame when editor markers are present, then remove editor markers.

  • private void __AssignQueries(ref SystemState state)
    Called from OnCreateForCompiler; currently creates and disposes a temporary EntityQueryBuilder (placeholder) — part of compiler-generated initialization. It may be a stub left by the compiler.

  • protected override void OnCreateForCompiler()
    Compiler helper invoked to initialize query and handle state for generated code paths:

  • Calls __AssignQueries(ref base.CheckedStateRef).
  • Calls __TypeHandle.__AssignHandles(ref base.CheckedStateRef).

  • (nested) TypeHandle.__AssignHandles(ref SystemState state)
    Initializes the EntityTypeHandle, ComponentTypeHandle, and ComponentLookup handles using the provided SystemState.

  • (nested) CheckLanesJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Performs the chunk-level processing described above. Internals:

  • Gets NativeArray for the chunk entity array.
  • Gets NativeArray for the chunk Owner component array.
  • Iterates entries: for each Owner value, checks if owner.m_Owner entity has an EditorContainer component (via m_EditorContainerData.HasComponent).
    • If true: if m_OwnerData.TryGetComponent(owner.m_Owner, out var componentData) is successful, set that Owner component on the lane entity using the command buffer; otherwise remove Owner component from the lane entity.

Notes: - The job implements IJobChunk explicitly (IJobChunk.Execute), calling the internal Execute method. - The job is marked with [BurstCompile] in the file; this improves performance when compiled with Burst.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // This mirrors what FilterLoadedSystem does: cache systems and queries on creation.
    m_LoadGameSystem = World.GetOrCreateSystemManaged<LoadGameSystem>();
    m_NetLaneQuery = GetEntityQuery(ComponentType.ReadOnly<Lane>(), ComponentType.ReadOnly<Owner>());
    m_EditorContainerQuery = GetEntityQuery(ComponentType.ReadOnly<EditorContainer>());
}

Notes for modders: - This system acts only when LoadGameSystem.context.purpose == Purpose.NewGame and EditorContainer entities exist; it is specifically for filtering/cleaning up data created in editor mode while starting a new game. - The core lane-owner fixes are applied via an EntityCommandBuffer scheduled from a Burst-compiled IJobChunk — this keeps it performant and safe for parallel execution. - If you need to extend or change this behavior, be careful about thread-safety: component accesses inside the job use ComponentLookup/ComponentTypeHandle and the job writes via an ECB parallel writer. - Because the job is completed synchronously (.Complete()), this system will block until the fix-up is applied. If you remove .Complete() and rely on dependencies instead, ensure proper synchronization with subsequent systems that rely on the modified components.