Skip to content

Game.Tutorials.TutorialControlSchemeDeactivationSystem

Assembly:
Assembly-CSharp (game runtime assembly; exact assembly may vary by build/mod)

Namespace:
Game.Tutorials

Type:
class

Base:
TutorialDeactivationSystemBase

Summary:
This system deactivates tutorial entities when the player's active input control scheme no longer matches a tutorial's ControlSchemeActivationData. It targets both pending and active tutorials (depending on phase capability), schedules a parallel IJobChunk (DeactivateJob) to iterate matching chunks, and removes the TutorialActivated component from entities whose configured control scheme differs from InputManager.instance.activeControlScheme. The system uses an EntityCommandBuffer (parallel writer) and integrates with a barrier system to ensure safe structural changes.


Fields

  • private EntityQuery m_PendingTutorialQuery
    Used to select tutorial entities that are pending activation: have TutorialData, TutorialActivated and ControlSchemeActivationData but do NOT have TutorialActive, TutorialCompleted or ForceActivation. Populated in OnCreate.

  • private EntityQuery m_ActiveTutorialQuery
    Used to select tutorial entities that are currently active: have TutorialData, TutorialActivated, ControlSchemeActivationData and TutorialActive, but do NOT have TutorialCompleted or ForceActivation. Populated in OnCreate.

  • private TypeHandle __TypeHandle
    Container holding ComponentTypeHandle/EntityTypeHandle used by Burst-compiled jobs. Populated by __AssignHandles(ref SystemState) called from OnCreateForCompiler to cache handles for job scheduling.

  • (nested) private struct DeactivateJob (IJobChunk)
    Job data used to iterate chunks and remove the TutorialActivated component for entities whose ControlSchemeActivationData.m_ControlScheme does not match the current InputManager control scheme. Fields:

  • ComponentTypeHandle<ControlSchemeActivationData> m_ControlSchemeDeactivationType — read-only handle to the component data.
  • EntityTypeHandle m_EntityType — handle to read entity references.
  • InputManager.ControlScheme m_ControlScheme — the current active control scheme captured from InputManager.instance.
  • EntityCommandBuffer.ParallelWriter m_CommandBuffer — ECB parallel writer used to remove components safely from job threads.

  • (nested) private struct TypeHandle
    Holds component/entity type handles and provides an __AssignHandles(ref SystemState) helper used by OnCreateForCompiler to fetch the runtime handles.

Properties

  • None (no public properties exposed by this system)

Constructors

  • public TutorialControlSchemeDeactivationSystem()
    Default constructor (annotated with [Preserve] in source). No custom initialization beyond what the base constructor provides; initialization is performed in OnCreate / OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Initializes the system queries. It builds m_PendingTutorialQuery and m_ActiveTutorialQuery using the required combination of component includes/excludes so the system can later check and deactivate tutorials based on control scheme. Marked [Preserve] in source.

  • protected override void OnUpdate()
    Main update loop: verifies InputManager.instance is available, then calls CheckDeactivate on m_PendingTutorialQuery if there are pending tutorials; and on m_ActiveTutorialQuery if there are active tutorials and the base phaseCanDeactivate flag allows deactivation. Ensures no work is scheduled if InputManager.instance is null.

  • private void CheckDeactivate(EntityQuery query)
    Schedules the DeactivateJob (parallel IJobChunk) for the provided query if it is not empty. It fills jobData with:

  • component and entity type handles via InternalCompilerInterface.GetComponentTypeHandle / GetEntityTypeHandle,
  • the current InputManager.instance.activeControlScheme,
  • a parallel EntityCommandBuffer from the system's barrier system. The job is scheduled in parallel using JobChunkExtensions.ScheduleParallel and the produced dependency is registered with the barrier via m_BarrierSystem.AddJobHandleForProducer.

  • protected override void OnCreateForCompiler()
    Compiler / IL2CPP/Burst helper invoked to assign internal handles before runtime. Calls base.OnCreateForCompiler(), runs __AssignQueries and __TypeHandle.__AssignHandles to obtain ComponentTypeHandle/EntityTypeHandle values used by the Burst job.

  • private void __AssignQueries(ref SystemState state)
    A helper used by generated code / compiler-time initialization. In the provided source it constructs and disposes a temporary EntityQueryBuilder (likely a placeholder to enforce query assignment at compile-time). Kept for compatibility with generated handle assignment.

  • (nested) private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns the ComponentTypeHandle (read-only) and EntityTypeHandle from the given SystemState. Used to cache handles for the job.

  • (nested) private struct DeactivateJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Job execute logic: iterates entities in the chunk, reads ControlSchemeActivationData and Entity arrays, and for each entity whose ControlSchemeActivationData.m_ControlScheme differs from the captured m_ControlScheme, issues an ECB.RemoveComponent via the parallel command buffer for that entity index.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // set up queries similar to the system implementation
    m_PendingTutorialQuery = GetEntityQuery(
        ComponentType.ReadOnly<TutorialData>(),
        ComponentType.ReadOnly<TutorialActivated>(),
        ComponentType.ReadOnly<ControlSchemeActivationData>(),
        ComponentType.Exclude<TutorialActive>(),
        ComponentType.Exclude<TutorialCompleted>(),
        ComponentType.Exclude<ForceActivation>());

    m_ActiveTutorialQuery = GetEntityQuery(
        ComponentType.ReadOnly<TutorialData>(),
        ComponentType.ReadOnly<TutorialActivated>(),
        ComponentType.ReadOnly<ControlSchemeActivationData>(),
        ComponentType.ReadOnly<TutorialActive>(),
        ComponentType.Exclude<TutorialCompleted>(),
        ComponentType.Exclude<ForceActivation>());
}

[Preserve]
protected override void OnUpdate()
{
    if (InputManager.instance == null)
        return;

    if (!m_PendingTutorialQuery.IsEmptyIgnoreFilter)
        CheckDeactivate(m_PendingTutorialQuery);

    if (!m_ActiveTutorialQuery.IsEmptyIgnoreFilter && base.phaseCanDeactivate)
        CheckDeactivate(m_ActiveTutorialQuery);
}

Notes: - This system relies on InputManager.instance.activeControlScheme being available at runtime. - Structural changes are executed via an EntityCommandBuffer created from the system's barrier (m_BarrierSystem) and scheduled as a parallel job to maintain performance and thread safety. - The presence of OnCreateForCompiler, __AssignQueries and TypeHandle is related to code-generation / Burst-friendly patterns used by Unity.Entities and the game's build pipeline.