Skip to content

Contexts and System Ownership

A TunalContext groups the simulation systems that describe one world or environment. Objects bind to that context to obtain a consistent time, calendar, and related state. Use explicit context references when an object could otherwise belong to more than one simulation.

A context is an owner and startup coordinator, not a requirement that every Tunal system be present. The supplied context prefab is the easiest way to start with connected references.

Keep systems within their owner

The context's Inspector lists Time (Required) and the optional Calendar, Astronomy, Seasons, Day Phases, and Lunar assignments.

Each assigned system must belong to this context's hierarchy. A system inside a nested TunalContext belongs to that nested context, not the outer one. Assigning a system from another context is an error, even if the reference is visible in the Inspector.

Automatic discovery searches children, including inactive children, without crossing nested-context ownership boundaries. It fills missing references and preserves existing assignments. If a missing slot has multiple matching owned systems, discovery reports ambiguity; assign the intended reference explicitly or remove the unintended duplicate.

Inactive objects can be discovered, but discovery does not enable them. The required Time System must be active and enabled for initialization.

Understand system dependencies

Module Context-managed prerequisites
Time Enabled Time System; required for the context
Calendar Time and a valid calendar configuration
Astronomy Enabled, initialized Calendar and a valid Astronomical Profile
Seasons Calendar and a valid Season Profile; astronomical-cycle profiles also need initialized Astronomy
Day Phases Enabled, initialized Astronomy and a valid Day Phase Profile
Lunar Enabled, initialized Astronomy and Calendar, plus a valid Lunar Profile

Optional means you can omit the module. It does not mean an enabled module works without its prerequisites. An unavailable optional module produces a warning while independent modules continue running.

Inspect Module Status in Play Mode to see what is actually ready. A context reporting IsInitialized does not certify every optional module.

Initialization and refresh

The context discovers references in Awake and initializes from Start, before ordinary Start callbacks through its configured execution order. This allows listeners subscribed during scene Awake/OnEnable to receive initial state events.

Initialize() can also be called explicitly, for example after instantiating a context. It returns false if required validation or clock initialization fails. After success, repeated calls return true without replaying onInitialized.

Use the Inspector's Find Missing Child Systems after editing a hierarchy with missing assignments. During Play Mode, Refresh Optional Modules calls RefreshSystems() to discover missing systems and initialize available modules. A successful refresh publishes onSystemsRefreshed, not the original initialization event. It is not an instruction to clear valid explicit assignments or reset the clock.

These rules describe context-managed startup. You do not need to call every system's initialization method manually in the prefab workflow.

Bind objects deliberately

Simulation ownership and consumer binding are different:

  • A system belongs to the nearest owning context hierarchy.
  • A reactive or lifecycle object can reference a context explicitly when it lives elsewhere in the scene.
  • A presentation group selects the context its inheriting visual controllers consume; it does not transfer system ownership.

Do not use the singleton prefab as the starting point for several independent contexts. SingletonTunalContext enforces a single instance and can persist its root between scene loads. Ordinary TunalContext instances are the appropriate basis for the multi-context workflow.

Common configuration mistakes

  • Missing/disabled Time System: assign and enable it before initializing.
  • A system assigned from another world: move or reassign it so its nearest owning context is correct.
  • Expecting discovery to choose between duplicates: configure an unambiguous hierarchy or assign the intended system.
  • Assuming successful startup means all modules work: inspect module status and the specific dependency/profile warning.