Game.InitializeAnimatedSystem
Assembly: Assembly-CSharp
Namespace: Game.Rendering
Type: class
Base: GameSystemBase
Summary:
InitializeAnimatedSystem is an ECS system used to initialize and maintain Animated buffers for entities that are marked as animated by the PreCullingSystem. It coordinates with PreCullingSystem to get the set of updated/near-camera entities, and with AnimatedSystem to allocate/release bone and meta buffer resources. Work is performed inside a Burst-compiled IJob (InitializeAnimatedJob) which reads various prefab and rendering buffers (submeshes, submesh groups, character elements, overlays, mesh colors, animation clips) and writes DynamicBuffer
Fields
-
private AnimatedSystem m_AnimatedSystem
Reference to the game's AnimatedSystem. Used to allocate/release bone/meta buffer resources and to obtain allocation data for the scheduled job. -
private PreCullingSystem m_PreCullingSystem
Reference to the PreCullingSystem. The system provides the PreCullingData list (m_CullingData) that the job inspects to decide which entities need animated buffer initialization or removal. -
private TypeHandle __TypeHandle
Holds ComponentLookup/BufferLookup handles used to access component and buffer data inside the job. It is assigned in OnCreateForCompiler and used in OnUpdate to build the job's lookup fields.
Properties
- This system exposes no public properties.
Constructors
public InitializeAnimatedSystem()
Default constructor. Marked with [Preserve]. Typical ECS-managed system construction; most initialization is done in OnCreate (resolving other systems).
Methods
-
protected override void OnCreate()
Registers/gets references to the AnimatedSystem and PreCullingSystem from the World (m_AnimatedSystem and m_PreCullingSystem). Marked with [Preserve]. -
protected override void OnUpdate()
Builds and schedules the Burst-compiled InitializeAnimatedJob. It: - Acquires component and buffer lookups via the TypeHandle.
- Gets the updated culling data from PreCullingSystem and allocation data from AnimatedSystem (both returning dependencies).
- Schedules InitializeAnimatedJob with combined dependencies (base.Dependency + readers/writers).
- Registers the returned JobHandle with AnimatedSystem (AddAllocationWriter) and PreCullingSystem (AddCullingDataReader).
-
Assigns the scheduled JobHandle to base.Dependency so further systems wait appropriately.
-
private void __AssignQueries(ref SystemState state)
Generated helper for query assignment (no query used here; it constructs/disposes an EntityQueryBuilder). Called from OnCreateForCompiler. -
protected override void OnCreateForCompiler()
Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles to set up lookups before runtime. -
(Nested) InitializeAnimatedJob : IJob (BurstCompile)
Summary: iterates m_CullingData (PreCullingData array) and for each entry with Animated flag and updated flags it either removes or updates the DynamicBufferfor the entity. - Fields read by the job: ComponentLookup
, ComponentLookup , BufferLookup , BufferLookup , BufferLookup , BufferLookup , BufferLookup , BufferLookup , BufferLookup . - Buffer written: BufferLookup
(Writable). - Accesses: NativeList
m_CullingData (read-only) and AnimatedSystem.AllocationData m_AllocationData (for allocating/releasing bones and meta buffer data). -
Key internal methods:
Execute()
Iterates m_CullingData; for each entry where flags indicate Animated and updated (or near-camera updated changes), calls Update or Remove.Remove(PreCullingData cullingData)
Clears and deallocates any bone/meta allocations in the entity's Animated buffer.Update(PreCullingData cullingData)
Complex logic that:- Looks up PrefabRef for the entity.
- Tries to obtain SubMesh buffer for the prefab; if absent, removes Animated data.
- Determines number of animated entries (per mesh group or default 1).
- Deallocates previous animated entries, resizes the buffer, and for each Animated entry:
- If character elements exist, allocates bones via m_AllocationData, builds MetaBufferData (bone offset/count, shape counts, shape/texture/overlay/mask weights).
- Collects overlay elements for the submesh group and sorts overlay weights (using stackalloc OverlayIndex[8] and NativeSortExtension.Sort).
- Reads overlay colors from meshColors (if available) and stores them in meta buffer data.
- Adds meta buffer data to allocation data and stores returned index in Animated.
- Determines initial clip indices if animation clips are present on the entity and based on animation layer mask.
- Writes populated Animated entries back to the entity's DynamicBuffer
.
Deallocate(DynamicBuffer<Animated> animateds)
Releases any bone allocations and meta buffer entries present in the Animated entries.AddOverlayIndex(OverlayIndex* overlayIndex, int index, DynamicBuffer<OverlayElement> overlayElements, BlendWeight weight)
Helper that populates an OverlayIndex entry with sort order and weight for later sorting.GetOverlayColor(OverlayIndex* overlayIndex, int index, DynamicBuffer<MeshColor> meshColors, int colorOffset)
Helper that returns overlay Color from meshColors if available, otherwise Color.white.
-
(Nested) OverlayIndex : IComparable
Small struct used for sorting up to 8 overlay weights by the overlay element sort order. Implements CompareTo comparing sort order primarily, falling back to original index. -
(Nested) TypeHandle
Contains ComponentLookup/BufferLookup fields and __AssignHandles(ref SystemState state) to initialize lookups via state.GetComponentLookup() calls. The system uses this to create the lookups passed into the job.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_AnimatedSystem = base.World.GetOrCreateSystemManaged<AnimatedSystem>();
m_PreCullingSystem = base.World.GetOrCreateSystemManaged<PreCullingSystem>();
}
Notes / Tips: - The heavy work is done inside a Burst-compiled IJob to keep main-thread work minimal; changes to ComponentLookup/BufferLookup usage must respect thread-safety and readonly/writeable semantics. - The job interacts with AnimatedSystem.AllocationData; ensure any changes to allocation APIs keep the AddMetaBufferData / AllocateBones / ReleaseBones semantics consistent. - Overlay sorting uses a fixed-size stack-allocated array of 8 entries — character overlay weights assume up to 8 overlay channels. Adjust with care if overlays change.