Skip to content

Game.Serialization.SubObjectSystem

Assembly:
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
SubObjectSystem is a compiler-generated Unity ECS system that collects sub-object relationships at the end of a frame (via a scheduled IJobChunk). It finds entities that are Game.Objects.Object and either have an Owner or Attached component (but are not Vehicles or Creatures), and populates the Owner's SubObject dynamic buffer. The system uses a Burst-compiled job (SubObjectJob) and buffer lookups for efficient chunked processing. It also contains a generated TypeHandle helper to cache the various Entity/Component/Buffer handles required by the job.


Fields

  • private EntityQuery m_Query
    Used to select entities processed by the system. The query matches entities with Game.Objects.Object and either Owner or Attached, while excluding Vehicle and Creature.

  • private TypeHandle __TypeHandle
    Holds the generated component/entity/buffer handles used to build the job (see TypeHandle struct below). Populated via __AssignHandles when the system is created for the compiler.

Nested Types

  • private struct SubObjectJob : IJobChunk
  • Attributes: [BurstCompile]
  • Fields:
    • EntityTypeHandle m_EntityType (ReadOnly) — handle to read entity IDs for a chunk.
    • ComponentTypeHandle<Owner> m_OwnerType (ReadOnly) — handle to read Owner components.
    • ComponentTypeHandle<Attached> m_AttachedType (ReadOnly) — handle to read Attached components.
    • BufferLookup<SubObject> m_SubObjects — buffer lookup used to obtain the SubObject dynamic buffer from owner/parent entities.
  • Behavior (Execute):

    • Retrieves the native arrays for Entity, Owner and Attached from the chunk.
    • For each entity with an Owner component, it attempts to GetBuffer on owner.m_Owner and adds a new SubObject(entity) to that buffer. If the owner has no SubObject buffer, it logs a debug message including the sub-object entity index/version.
    • For each entity with an Attached component, it attempts to GetBuffer on attached.m_Parent and uses CollectionUtils.TryAddUniqueValue to add a new SubObject(entity) while preventing duplicates.
    • Implements IJobChunk.Execute by forwarding to its Execute method.
  • private struct TypeHandle

  • Fields:
    • EntityTypeHandle __Unity_Entities_Entity_TypeHandle (ReadOnly)
    • ComponentTypeHandle<Owner> __Game_Common_Owner_RO_ComponentTypeHandle (ReadOnly)
    • ComponentTypeHandle<Attached> __Game_Objects_Attached_RO_ComponentTypeHandle (ReadOnly)
    • BufferLookup<SubObject> __Game_Objects_SubObject_RW_BufferLookup
  • Methods:
    • __AssignHandles(ref SystemState state) — aggressive-inlined helper that populates the stored handles from the SystemState (GetEntityTypeHandle, GetComponentTypeHandle, GetBufferLookup).

Properties

  • (none)

Constructors

  • public SubObjectSystem()
  • Annotated with [Preserve]. Standard parameterless compiler-generated constructor for the system.

Methods

  • [Preserve] protected override void OnCreate()
  • Creates and stores an EntityQuery that:
    • All: ComponentType.ReadOnly()
    • Any: ComponentType.ReadOnly(), ComponentType.ReadOnly()
    • None: ComponentType.ReadOnly(), ComponentType.ReadOnly()
  • Calls RequireForUpdate(m_Query) so the system only runs when matching entities exist.
  • This is where the system subscribes to the set of entities it is intended to process.

  • [Preserve] protected override void OnUpdate()

  • Builds a SubObjectJob instance and populates its handles using InternalCompilerInterface.Get... methods based on the cached __TypeHandle and the system's CheckedStateRef.
  • Schedules the job via JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the returned JobHandle to base.Dependency.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)

  • Generated helper invoked by OnCreateForCompiler. In this generated code it currently only creates and disposes a temporary EntityQueryBuilder (likely placeholder/side-effect for proper JIT/IL generation).

  • protected override void OnCreateForCompiler()

  • Calls __AssignQueries and __TypeHandle.__AssignHandles to ensure the compiler-time initialization of handles for ahead-of-time usage.

  • void IJobChunk.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) (in SubObjectJob)

  • Interface implementation that forwards to the job's Execute method.

Usage Example

The system is compiler-generated and runs automatically once added to the world. Typical data layout expected by the system:

  • An owner entity must have a SubObject dynamic buffer (Buffer) so sub-objects can be appended to it.
  • Sub-objects are entities with an Owner or Attached component pointing to the owner/parent entity.

Example showing how such entities might be created so SubObjectSystem will populate the owner's buffer:

// Pseudocode / example usage in an ECS initialization context:
var em = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create an owner entity that holds a SubObject buffer
Entity owner = em.CreateEntity(typeof(Game.Objects.Object));
em.AddBuffer<SubObject>(owner); // ensure owner has the SubObject buffer

// Create a sub-object and add an Owner component that references the owner
Entity sub = em.CreateEntity(typeof(Game.Objects.Object), typeof(Owner));
em.SetComponentData(sub, new Owner { m_Owner = owner });

// When SubObjectSystem runs, its job will detect the Owner on `sub` and append a new SubObject(sub) into the owner's SubObject buffer.

Notes: - The SubObjectJob is Burst-compiled and uses chunked processing for performance. - If an Owner referenced by a sub-object does not have a SubObject buffer, a debug log is produced listing the sub-object entity index and version. - Attached relationships use CollectionUtils.TryAddUniqueValue to avoid duplicate SubObject entries in the parent buffer.