Skip to content

Game.Objects.RelativeBoneSystem

Assembly: Assembly-CSharp (game)
Namespace: Game.Objects

Type: class

Base: GameSystemBase

Summary:
RelativeBoneSystem is a compiler-generated ECS system that updates entities that have a Relative component together with an Owner. For each Relative whose m_BoneIndex.x is non-zero, the system looks up the prefab referenced by the Owner, calls RenderingUtils.FindBoneIndex to resolve the bone position/rotation and fills the Relative.m_BoneIndex.yz with the returned bone index. The work is performed in a Burst-compiled Parallel IJobChunk (RelativeBoneJob) using ComponentTypeHandles, ComponentLookup, and BufferLookup for high performance. The system requires PrefabRef and the SubMesh/ProceduralBone buffers for the prefab to be present/readable.


Fields

  • private EntityQuery m_EntityQuery
    This EntityQuery matches entities that have a Relative (read/write) and an Owner (read-only). The query is created in OnCreate and required for system updates (RequireForUpdate).

  • private TypeHandle __TypeHandle
    Holds the ComponentTypeHandle/ComponentLookup/BufferLookup instances for use inside the Burst job. The nested TypeHandle struct contains:

  • ComponentTypeHandle (read-only)
  • ComponentTypeHandle (read/write)
  • ComponentLookup (read-only)
  • BufferLookup (read-only)
  • BufferLookup (read-only)

  • private struct RelativeBoneJob (nested)
    This Burst-compiled IJobChunk implementation performs the core per-chunk work:

  • Reads Relative and Owner arrays from the chunk.
  • For each element where Relative.m_BoneIndex.x != 0, it fetches the prefab via PrefabRef and calls RenderingUtils.FindBoneIndex(prefab, ref position, ref rotation, boneIndexX, ref m_PrefabSubMeshes, ref m_PrefabProceduralBones).
  • Writes the returned bone index into Relative.m_BoneIndex.yz.

  • private struct TypeHandle (nested)
    See above — contains the typed handles and a method to assign them from a SystemState.

Notes: - Several methods and types are annotated with [Preserve] and [CompilerGenerated] to keep them available for IL2CPP and the generated codepath. - The job uses several read-only/lookups to avoid unnecessary copying and to allow parallel scheduling.

Properties

  • (No public properties defined on this system)

Constructors

  • public RelativeBoneSystem()
    Default constructor preserved for runtime/IL2CPP. The real initialization happens in OnCreate/OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Creates the m_EntityQuery to match Relative (ReadWrite) and Owner (ReadOnly) and calls RequireForUpdate(m_EntityQuery) so the system only runs when matching entities exist.

  • protected override void OnUpdate()
    Builds and schedules the Burst-compiled RelativeBoneJob:

  • Populates jobData fields by asking the internal compiler interface for ComponentTypeHandle/ComponentLookup/BufferLookup using the stored __TypeHandle handles.
  • Schedules the job in parallel over m_EntityQuery via JobChunkExtensions.ScheduleParallel, chaining into base.Dependency.

  • protected override void OnCreateForCompiler()
    Called by the generated codepath to assign queries and typed handles at compile-time / codegen time. Calls __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state)
    Generated helper that can create/ensure queries. In this compiled build it creates and disposes an EntityQueryBuilder (unused here), but exists for codegen consistency.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns/initializes the ComponentTypeHandle/ComponentLookup/BufferLookup fields from the SystemState (GetComponentTypeHandle, GetComponentLookup, GetBufferLookup). Marked AggressiveInlining.

  • private struct RelativeBoneJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    The job's per-chunk execution method. Iterates the Relative/Owner arrays for the chunk and resolves bone indices using RenderingUtils.FindBoneIndex and prefab buffers/lookups. It contains the explicit IJobChunk Execute wrapper as well.

Notes on behavior and safety: - Owner and Relative ComponentTypeHandles are used with appropriate read-only / read-write flags. - PrefabRef and buffers are accessed through ComponentLookup and BufferLookup marked read-only. - The job is Burst-compiled and schedules in parallel; ensure any native container usage is compatible with Burst and job scheduling. - RenderingUtils.FindBoneIndex is called from the job; it expects a Prefab and BufferLookups for SubMesh and ProceduralBone to be valid and consistent.

Usage Example

// Example: create an entity that RelativeBoneSystem will process.
// Assumes Relative and Owner component types are defined and available.

var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

// Create an archetype with Relative and Owner
var archetype = entityManager.CreateArchetype(
    typeof(Game.Objects.Relative),
    typeof(Game.Common.Owner)
);

// Create an entity and set components
var e = entityManager.CreateEntity(archetype);

// Set Owner to point to an existing prefab entity (prefabEntity must exist in your context)
entityManager.SetComponentData(e, new Game.Common.Owner { m_Owner = prefabEntity });

// Initialize Relative.m_BoneIndex.x to the bone ID you want resolved.
// The system will fill m_BoneIndex.y and .z with the returned index info during update.
entityManager.SetComponentData(e, new Game.Objects.Relative { m_BoneIndex = new Unity.Mathematics.int3(boneId, -1, -1) });

// The RelativeBoneSystem runs automatically as part of the ECS update loop and will
// call RenderingUtils.FindBoneIndex for this entity and write results into its Relative component.

Additional tips: - Ensure that the prefab entity referenced by Owner.m_Owner has a PrefabRef component and the SubMesh / ProceduralBone buffers populated — otherwise RenderingUtils.FindBoneIndex cannot resolve bones. - Because the work runs in a Burst IJobChunk scheduled in parallel, keep any managed or UnityEngine objects out of the job code; rely on Lookups/Handles and native containers. - The system is compiler-generated and uses internal-binding helpers (InternalCompilerInterface) — modifying this system directly in a mod is typically unnecessary; instead ensure your entities/components meet the expected layout.