Skip to content

Game.AnimationSystem

Assembly: Game (game assembly containing game systems; may appear in Assembly-CSharp in modding environments)
Namespace: Game.Tools

Type: class (marked [CompilerGenerated])

Base: GameSystemBase

Summary:
AnimationSystem is an ECS system that updates Animation components each frame by sampling the corresponding Game.Objects.Transform and applying a procedural "sway" effect. The per-chunk work is performed by a Burst-compiled IJobChunk (AnimateJob) scheduled in parallel. The system queries entities that have an Animation component and a read-only Transform and excludes entities marked Deleted. Internally it uses ComponentTypeHandle instances (via a nested TypeHandle struct and InternalCompilerInterface helper) and updates base.Dependency with the scheduled JobHandle.


Fields

  • private EntityQuery m_AnimatedQuery
    Used to select entities to update: ReadWrite Animation, ReadOnly Game.Objects.Transform, and excluding Deleted. This query is created in OnCreate and passed to JobChunk scheduling in OnUpdate.

  • private TypeHandle __TypeHandle
    Holds ComponentTypeHandle instances used by the AnimateJob: a read-only handle for Game.Objects.Transform and a read-write handle for Animation. The nested TypeHandle struct provides an __AssignHandles method to initialize these from a SystemState.

Properties

  • None (no public properties on this system)

Constructors

  • public AnimationSystem()
    Default constructor. Marked with [Preserve] attribute on lifecycle methods; class itself is compiler-generated and the constructor does not perform initialization beyond base construction. Initialization is done in OnCreate/OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Creates and configures the m_AnimatedQuery:
  • Query: ComponentType.ReadWrite(), ComponentType.ReadOnly(), ComponentType.Exclude().
  • Calls RequireForUpdate(m_AnimatedQuery) so the system only updates when matching entities exist.
  • Calls base.OnCreate().

  • protected override void OnUpdate()
    Builds and schedules the AnimateJob (Burst compiled) using JobChunkExtensions.ScheduleParallel against m_AnimatedQuery. It:

  • Sets AnimateJob.m_DeltaTime to UnityEngine.Time.deltaTime.
  • Acquires ComponentTypeHandle instances via InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle..., ref base.CheckedStateRef).
  • Schedules the job in parallel and assigns the returned JobHandle to base.Dependency.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper that can initialize or prepare queries; in the compiled code it contains a call to new EntityQueryBuilder(Allocator.Temp).Dispose() (placeholder) — the real queries are created in OnCreate. This method is invoked from OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Compiler-time initialization used by generated code. Calls base.OnCreateForCompiler(), then:

  • Calls __AssignQueries(ref base.CheckedStateRef) to ensure queries are known to the compiler.
  • Calls __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to initialize the internal ComponentTypeHandle fields.

Nested types (behavioral summary)

  • private struct AnimateJob : IJobChunk (BurstCompile)
    Performs the per-entity sway animation update inside Execute:
  • Reads arrays of Game.Objects.Transform (read-only) and Animation (read-write) for the chunk.
  • For each entity:
    • Accumulates sway velocity using difference between stored target position and current transform position scaled by m_PushFactor.
    • Resets target position to current transform position and zeroes m_PushFactor.
    • Applies exponential damping to m_SwayVelocity using math.pow(0.0001f, deltaTime).
    • Applies a restorative force proportional to m_SwayPosition.
    • Integrates velocity into m_SwayPosition and applies a non-linear clamp: m_SwayPosition = atan(m_SwayPosition * 0.02f) * 50f.
    • Computes a small Euler rotation from the sway (quaternion.EulerZXY) and composes it with the transform rotation to get value.m_Rotation.
    • Computes a pivot-corrected position and lerps value.m_Position toward it with a very fast decay factor.
  • Uses Unity.Mathematics for float3/quaternion math; job is scheduled in parallel across chunks.

  • private struct TypeHandle
    Contains:

  • ComponentTypeHandle<Game.Objects.Transform> (read-only)
  • ComponentTypeHandle<Animation> (read-write)
  • Method __AssignHandles(ref SystemState state) which populates the handles via state.GetComponentTypeHandle(isReadOnly: ...) so the job can query chunk component arrays efficiently.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Create the query to select animated entities (Animation + Transform, exclude Deleted)
    m_AnimatedQuery = GetEntityQuery(
        ComponentType.ReadWrite<Animation>(),
        ComponentType.ReadOnly<Game.Objects.Transform>(),
        ComponentType.Exclude<Deleted>()
    );
    RequireForUpdate(m_AnimatedQuery);
}

[Preserve]
protected override void OnUpdate()
{
    // Schedule the Burst-compiled AnimateJob in parallel for the matching entities
    JobHandle dependency = JobChunkExtensions.ScheduleParallel(new AnimateJob
    {
        m_DeltaTime = UnityEngine.Time.deltaTime,
        m_TransformType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Objects_Transform_RO_ComponentTypeHandle, ref base.CheckedStateRef),
        m_AnimationType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Tools_Animation_RW_ComponentTypeHandle, ref base.CheckedStateRef)
    }, m_AnimatedQuery, base.Dependency);

    base.Dependency = dependency;
}

Notes and implementation tips: - The heavy math (atan, pow, quaternion operations) is done inside the Burst-compiled job for performance on many entities. - Ensure the Animation component layout matches what AnimateJob expects (fields like m_SwayVelocity, m_TargetPosition, m_PushFactor, m_SwayPosition, m_SwayPivot, m_Rotation, m_Position). - The system uses InternalCompilerInterface.GetComponentTypeHandle to obtain handles compatible with the compiled code path — when adapting or copying this pattern, mirror how handles and SystemState are used to avoid safety/compatibility issues.