Skip to content

Game.Tutorials.TutorialTriggerSystem

Assembly: Assembly-CSharp
Namespace: Game.Tutorials

Type: class

Base: GameSystemBase, IPreDeserialize

Summary:
Manages and coordinates multiple TutorialTriggerSystemBase implementations. On creation it collects all concrete tutorial trigger subsystems (object placement, input, area, selection, upgrade, UI, policy adjustment, zoning) and maintains an EntityQuery for entities that contain TutorialTriggerData. The system is only enabled in game mode and, each update, forwards Update() calls to each contained subsystem while catching and logging exceptions. It also implements IPreDeserialize to clear trigger-related components before deserialization, ensuring tutorial triggers are reset appropriately during load.


Fields

  • private readonly System.Collections.Generic.List<TutorialTriggerSystemBase> m_Systems
    Holds the instantiated tutorial trigger subsystems retrieved via base.World.GetOrCreateSystemManaged(). The list includes systems such as:
  • TutorialObjectPlacementTriggerSystem
  • TutorialInputTriggerSystem
  • TutorialAreaTriggerSystem
  • TutorialObjectSelectionTriggerSystem
  • TutorialUpgradeTriggerSystem
  • TutorialUITriggerSystem
  • TutorialPolicyAdjustmentTriggerSystem
  • TutorialZoningTriggerSystem
    Useful for delegating Update() calls to all registered trigger subsystems.

  • private Unity.Entities.EntityQuery m_TriggerQuery
    EntityQuery configured to find entities with the TutorialTriggerData component (ComponentType.ReadOnly), used by PreDeserialize to remove trigger-related components from matching entities.

Properties

  • None (no public properties exposed).

Constructors

  • public TutorialTriggerSystem()
    Parameterless constructor with the [Preserve] attribute. The real initialization happens in OnCreate; constructor itself is empty.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system:
  • Calls base.OnCreate().
  • Adds each tutorial trigger subsystem to m_Systems by calling base.World.GetOrCreateSystemManaged() for each concrete subsystem type.
  • Creates m_TriggerQuery = GetEntityQuery(ComponentType.ReadOnly()).
  • Sets base.Enabled = false so the system doesn't run until allowed (OnGamePreload will enable it if in game mode).

  • protected override void OnGamePreload(Purpose purpose, GameMode mode) : System.Void
    Called during game preload. Enables or disables the system depending on whether the current GameMode is a game mode:

  • base.Enabled = mode.IsGame();

  • protected override void OnUpdate() : System.Void
    Main update loop executed while the system is enabled. Iterates the m_Systems list and calls system.Update() on each TutorialTriggerSystemBase. Each call is wrapped in a try/catch — exceptions are logged via COSystemBase.baseLog.Critical(exception) so a failure in one subsystem does not prevent others from updating.

  • public void PreDeserialize(Context context) : System.Void
    IPreDeserialize implementation called before entity deserialization. Removes the following components from all entities matching m_TriggerQuery:

  • TriggerActive
  • TriggerPreCompleted
  • TriggerCompleted
  • TutorialNextPhase
    This resets trigger activation/completion state so that tutorial triggers are in a clean state when a save is loaded or deserialization happens.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // The system adds its subsystems and sets up the entity query for TutorialTriggerData.
    // If you need to add a custom tutorial trigger system, you can do so here:
    m_Systems.Add(base.World.GetOrCreateSystemManaged<MyCustomTutorialTriggerSystem>());
    m_TriggerQuery = GetEntityQuery(ComponentType.ReadOnly<TutorialTriggerData>());
    base.Enabled = false;
}

{{ ADDITIONAL_INFO }} - Typical use for modders: - To add custom tutorial triggers, implement a TutorialTriggerSystemBase-derived system and register it via World.GetOrCreateSystemManaged() (call from your system's OnCreate or via a mod initialization routine). - If you need custom serialization behavior for tutorial triggers, hook into PreDeserialize or provide your own serialization handling for the Trigger* components. - Be aware that this system runs only when the game mode is a playable game (mode.IsGame()), so testing code should ensure the correct mode or manually enable the system for editor/debugging. - Key ECS components referenced: - TutorialTriggerData (used to identify trigger entities) - TriggerActive, TriggerPreCompleted, TriggerCompleted, TutorialNextPhase (removed during PreDeserialize to reset state) - Error handling: subsystem Update() calls are isolated with try/catch; exceptions are logged with COSystemBase.baseLog.Critical, preventing a single failing subsystem from stopping the overall update loop.