Skip to content

Game.TutorialControlSchemeActivationSystem

Assembly: Assembly-CSharp
Namespace: Game.Tutorials

Type: class

Base: GameSystemBase

Summary:
System that activates tutorials based on the current input control scheme. It queries for tutorial entities that have ControlSchemeActivationData (and TutorialData) and that are not yet completed or already activated. When the active control scheme (from InputManager.instance.activeControlScheme) matches a tutorial's ControlSchemeActivationData, the system schedules a parallel chunk job (Burst compiled) that adds the TutorialActivated component to the matching entities via an EntityCommandBuffer. The system uses a ModificationBarrier4-derived EntityCommandBufferSystem for safe, parallel command recording and proper dependency handling.


Fields

  • private EntityCommandBufferSystem m_BarrierSystem
    Holds the modification barrier system used to create command buffers for recording structural changes (adding TutorialActivated). In this class it is populated in OnCreate using World.GetOrCreateSystemManaged().

  • private EntityQuery m_TutorialQuery
    The query selects tutorial entities to process:

  • ReadOnly
  • ReadOnly
  • Exclude
  • Exclude Only entities matching this query are considered for activation.

  • private TypeHandle __TypeHandle
    Internal helper struct that caches ComponentTypeHandle and EntityTypeHandle for use inside the job. It is assigned via __AssignHandles(ref SystemState) during system setup/OnCreateForCompiler.

Properties

  • (none)

Constructors

  • public TutorialControlSchemeActivationSystem()
    Default parameterless constructor. Marked [Preserve] in the original source to avoid stripping.

Methods

  • protected override void OnCreate()
    Initializes the system: acquires the ModificationBarrier4 (m_BarrierSystem) and constructs the EntityQuery (m_TutorialQuery) that finds tutorials with ControlSchemeActivationData and TutorialData, excluding already completed or activated tutorials.

  • protected override void OnUpdate()
    Main update logic:

  • Checks that m_TutorialQuery is not empty and that InputManager.instance is available.
  • Builds an ActivateJob which:
    • Reads ControlSchemeActivationData and Entity handles.
    • Reads InputManager.instance.activeControlScheme into m_ControlScheme.
    • Uses an EntityCommandBuffer.ParallelWriter to add TutorialActivated to matching entities.
  • Schedules the job in parallel with JobChunkExtensions.ScheduleParallel and sets base.Dependency.
  • Registers the resulting dependency with m_BarrierSystem by calling AddJobHandleForProducer.

  • protected override void OnCreateForCompiler()
    Compiler-time helper: calls __AssignQueries and assigns handles on the __TypeHandle. Used by generated/IL2CPP-friendly patterns.

  • private void __AssignQueries(ref SystemState state)
    Internal (compiler generated) method that can be used to initialize queries in a way compatible with the compiler-generated system codepath. In the source it creates and disposes an EntityQueryBuilder(Allocator.Temp).

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns:

  • ComponentTypeHandle (read-only)
  • EntityTypeHandle Used to populate the __TypeHandle for job use; marked with [MethodImpl(MethodImplOptions.AggressiveInlining)] in source.

  • Nested: ActivateJob : IJobChunk (private, BurstCompile)
    Job executed per chunk:

  • Fields:
    • ComponentTypeHandle m_ControlSchemeActivationType (ReadOnly)
    • EntityTypeHandle m_EntityType (ReadOnly)
    • InputManager.ControlScheme m_ControlScheme
    • EntityCommandBuffer.ParallelWriter m_Writer
  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    • Iterates the chunk's ControlSchemeActivationData and Entity arrays.
    • For each element where m_ControlScheme == data.m_ControlScheme, calls m_Writer.AddComponent(unfilteredChunkIndex, entity) to mark activation.
  • Implements IJobChunk.Execute by forwarding to its own Execute method.
  • Burst compiled for performance.

Notes about the job and concurrency: - The job uses AsParallelWriter() on the command buffer so it can safely run in parallel across chunks. The unfilteredChunkIndex is passed as the sort key in AddComponent calls. - ComponentTypeHandle and EntityTypeHandle are retrieved via InternalCompilerInterface.GetComponentTypeHandle / GetEntityTypeHandle in OnUpdate to respect the system state's safety checks.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_BarrierSystem = base.World.GetOrCreateSystemManaged<ModificationBarrier4>();
    m_TutorialQuery = GetEntityQuery(
        ComponentType.ReadOnly<TutorialData>(),
        ComponentType.ReadOnly<ControlSchemeActivationData>(),
        ComponentType.Exclude<TutorialCompleted>(),
        ComponentType.Exclude<TutorialActivated>()
    );
}

[Preserve]
protected override void OnUpdate()
{
    if (!m_TutorialQuery.IsEmptyIgnoreFilter && InputManager.instance != null)
    {
        var jobData = new ActivateJob
        {
            m_ControlSchemeActivationType = InternalCompilerInterface.GetComponentTypeHandle(
                ref __TypeHandle.__Game_Tutorials_ControlSchemeActivationData_RO_ComponentTypeHandle,
                ref base.CheckedStateRef),
            m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(
                ref __TypeHandle.__Unity_Entities_Entity_TypeHandle,
                ref base.CheckedStateRef),
            m_ControlScheme = InputManager.instance.activeControlScheme,
            m_Writer = m_BarrierSystem.CreateCommandBuffer().AsParallelWriter()
        };

        base.Dependency = JobChunkExtensions.ScheduleParallel(jobData, m_TutorialQuery, base.Dependency);
        m_BarrierSystem.AddJobHandleForProducer(base.Dependency);
    }
}

Additional notes and tips: - The system requires InputManager.instance to be available; otherwise nothing is scheduled. - The system adds TutorialActivated to entities whose ControlSchemeActivationData.m_ControlScheme equals InputManager.instance.activeControlScheme. - Because structural changes are recorded via the barrier system, ensure the barrier (ModificationBarrier4) exists in the world; it is created/queried in OnCreate. - The code uses compiler-generated/internal helpers (InternalCompilerInterface, CheckedStateRef) typical for DOTS authoring patterns; when writing custom systems follow DOTS patterns for creating ComponentTypeHandles and scheduling chunk jobs.