Skip to content

Game.Tutorials.TutorialUIDeactivationSystem

Assembly:
Assembly-CSharp (typical runtime assembly for game code; adjust if your build uses a different assembly)
Namespace: Game.Tutorials

Type: class

Base: TutorialDeactivationSystemBase, ITutorialUIDeactivationSystem

Summary:
System that deactivates tutorial UI activations by tag. It monitors tutorial entities that contain UI activation data and a prefab reference, checks their UI tag string(s) and removes the TutorialActivated component when a matching tag has been requested for deactivation. Uses the game's PrefabSystem to read the tutorial prefab UI tag, and issues structural changes through an EntityCommandBuffer from the barrier system provided by the base class. Designed to handle both pending and active tutorial entities and respects the base class' phaseCanDeactivate for active tutorials.


Fields

  • private PrefabSystem m_PrefabSystem
    Reference to the game's PrefabSystem used to resolve TutorialPrefab instances and read their TutorialUIActivation component (to obtain the uiTag).

  • private readonly HashSet<string> m_Deactivate = new HashSet<string>()
    A set of string tags requested for deactivation this frame. Tags are compared against the prefab uiTag entries (split by '|', trimmed). Cleared at the end of OnUpdate.

  • private EntityQuery m_PendingTutorialQuery
    EntityQuery that matches tutorial entities that are pending activation (contain UIActivationData, TutorialData, TutorialActivated, PrefabData; exclude TutorialActive, TutorialCompleted, ForceActivation). Used to find pending tutorials to deactivate.

  • private EntityQuery m_ActiveTutorialQuery
    EntityQuery that matches active tutorial entities (contain UIActivationData, TutorialData, TutorialActivated, PrefabData, TutorialActive; exclude TutorialCompleted, ForceActivation). Used to find active tutorials to deactivate when the system phase allows it.

Properties

  • None.

Constructors

  • public TutorialUIDeactivationSystem()
    Default constructor. Marked with [Preserve] attribute on the class and C# generated attribute for compatibility with managed systems. No custom initialization beyond what is done in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains the PrefabSystem from the world and builds two EntityQuery objects:
  • m_PendingTutorialQuery: for pending tutorial UI activations (not yet active).
  • m_ActiveTutorialQuery: for currently active tutorial UI activations. These queries filter entities by the presence/absence of components (UIActivationData, TutorialData, TutorialActivated, PrefabData, TutorialActive, TutorialCompleted, ForceActivation). Called once when the system is created.

  • public void DeactivateTag(string tag)
    Adds the provided tag string to the m_Deactivate HashSet. Tags accumulated this frame will be used in OnUpdate to deactivate matching tutorials.

  • protected override void OnUpdate()
    Main update loop. If there are any tags in m_Deactivate:

  • Checks the pending tutorial query and calls CheckDeactivate for matches.
  • If the system's base phase allows deactivation (base.phaseCanDeactivate) and there are active tutorials, checks the active tutorial query as well. After processing, clears m_Deactivate. Notes:
  • Uses EntityQuery.IsEmptyIgnoreFilter to avoid unnecessary work.
  • The actual removal of TutorialActivated is done using an EntityCommandBuffer produced by the inherited barrier system.

  • private void CheckDeactivate(EntityQuery query)
    Performs the actual matching and deactivation for the provided query:

  • Converts the query results into NativeArray and NativeArray with Allocator.TempJob (must be disposed).
  • Iterates all matched entities and for each:
    • Resolves the TutorialPrefab via m_PrefabSystem.GetPrefab(prefabData).
    • Reads the TutorialUIActivation component's m_UITagProvider.uiTag string.
    • Splits uiTag by '|' into tag entries; if uiTag is null the entity is skipped.
    • Trims each tag entry and if it matches any tag in m_Deactivate, enqueues a command to remove the TutorialActivated component on that entity via the EntityCommandBuffer.
  • Disposes the native arrays after processing. Performance & safety notes:
  • Allocator.TempJob is used; arrays are disposed synchronously in this method — avoid long-running operations between allocation and disposal.
  • This method issues structural changes via an ECB (so changes will be applied later by the barrier system).
  • Tag matching is simple string equality on trimmed entries; tag strings are split by '|' in the prefab's uiTag.

Usage Example

// Request deactivation of tutorials whose prefab uiTag contains "myTag".
var uiDeactivation = World.DefaultGameObjectInjectionWorld
    .GetOrCreateSystemManaged<Game.Tutorials.TutorialUIDeactivationSystem>();
uiDeactivation.DeactivateTag("myTag");

// The system will process the request in its next OnUpdate, removing the TutorialActivated
// component from matching tutorial entities (pending or active, depending on phase).

Additional notes: - The system expects tutorial prefabs to provide their UI tag string via TutorialUIActivation.m_UITagProvider.uiTag; tags can be combined in the prefab with '|' separators (e.g., "tagA|tagB"). - Because the system removes TutorialActivated, other systems reacting to activation state changes should observe the resulting entity/component state the usual ECS way (after the barrier applies the changes).