Easy Chapter Generator
EnglishEspañol

Read the current snapshot safely

Use ChapterManager.Instance as the public observation boundary. A scene can exist before the singleton is ready, a Manager can have no selected Chapter, and a Chapter can have no active Objective after completion or failure. Check those states before dereferencing objects or displaying an ID.

Queries are instantaneous main-thread reads. They do not subscribe to future changes and do not force hydration again.

Observation properties

PropertyResult when absentUse
CurrentChapter / CurrentChapterIdnull / empty stringSelected Chapter identity
CurrentChapterStatenullable with no valueNotStarted, Active, Completed, or Failed
HasActiveChapterfalseFast Active-state guard
CurrentObjective / CurrentObjectiveIdnull / empty stringCurrent ordered record identity
CurrentObjectiveStatenullable with no valueNotStarted, Active, Completed, Skipped, or Failed
HasActiveObjectivefalseChapter and current row are both Active
IsTransitioningfalse before accepted transitionBlock conflicting project commands

Read after a known lifecycle point

  • After OnManagerReady for the initial state.
  • After a project command returns success.
  • Inside ChapterFailed when typed failure context is needed.
  • Before showing UI that depends on HasActiveObjective.
  • During diagnostics at a controlled interval, not by allocating strings every frame in production.

When listening to a component's own OnCompleted, remember the Chapter may already have advanced. Use captured pre-call context if the response needs the completed row rather than the new current row.

Avoid common query assumptions

CurrentObjectiveId is empty

This is valid when no Chapter is selected, a Chapter is terminal, or no current index resolves. Check nullable state and active flags.

Completed progress exists but no event fired on startup

Hydration does not replay historical events. Render the restored snapshot after readiness.

Polling shows a different row in OnCompleted

The Objective component's event runs after Chapter acceptance and advancement. Observe Chapter.ObjectiveCompleted(index) for the pre-action index.

Read the current progression state

Where to place it
Use this component on UI, telemetry or project-owned integration objects.
When to call it
Call TryReadCurrentProgress when the UI must refresh or after a lifecycle notification.
Behavior
This is an instantaneous main-thread read. It does not subscribe to future changes and returns false when no Objective is active.
using System;
using System.Collections;
using System.Collections.Generic;
using OverFuture.ChapterObjectiveSystem.Chapters;
using OverFuture.ChapterObjectiveSystem.Events;
using OverFuture.ChapterObjectiveSystem.Objectives;
using OverFuture.ChapterObjectiveSystem.Persistence;
using OverFuture.ChapterObjectiveSystem.Progression;
using UnityEngine;

public sealed class CurrentProgressReaderExample : MonoBehaviour
{
    public bool TryReadCurrentProgress(
        out string chapterId,
        out string objectiveId,
        out ChapterObjective.ObjectiveState objectiveState)
    {
        chapterId = string.Empty;
        objectiveId = string.Empty;
        objectiveState = ChapterObjective.ObjectiveState.NotStarted;

        ChapterManager manager = ChapterManager.Instance;
        if (manager == null || !manager.HasActiveObjective ||
            !manager.CurrentObjectiveState.HasValue)
        {
            return false;
        }

        chapterId = manager.CurrentChapterId;
        objectiveId = manager.CurrentObjectiveId;
        objectiveState = manager.CurrentObjectiveState.Value;
        return true;
    }
}