Events and execution behavior¶
An event tells you that a component reached a particular state boundary. It is not a guarantee that every dependent component or context has finished updating, and it is not a replay log.
Event reference¶
| Publisher | Events and payloads |
|---|---|
| TunalContext | onInitialized once after first successful startup; onSystemsRefreshed after successful refresh |
| Time | onTimeUpdate(float, TimeData), canonical minute/hour TimeData, onDayChanged(long), display update/minute/hour/configuration events with DisplayTimeData |
| Calendar | onDateChanged(DateData), onMonthChanged(int), onYearChanged(int) |
| Astronomy | onAstronomicalStateUpdated() |
| Day Phases | onPhaseUpdated(), onPhaseChanged(Phase) |
| Seasons | onSeasonStateUpdated(), onSeasonChanged(string stableSeasonId) |
| Lunar | onLunarStateUpdated() |
| Clouds / Stars | onCloudsUpdated(), onStarsUpdated() |
| Context switcher | onContextChanged(TunalContext) at initialized startup and changed selection |
| Lifecycle | Stage ID/progress UnityEvents plus completed/reset; C# StageChanged/ProgressChanged/LifecycleCompleted/LifecycleReset/StateReconciled |
Query the publisher's current properties when a no-payload event fires. Do not infer that onPhaseUpdated means a new named phase, or that a seasonal state update changes the primary season label.
Safe subscription example¶
Assign a fixed context to this observer. Its Readout can be consumed by your own display; it does not require a particular text backend:
using Sital.Tunal.Core;
using Sital.Tunal.Data;
using Sital.Tunal.Systems;
using UnityEngine;
namespace TunalExamples
{
public sealed class ClockObserver : MonoBehaviour
{
[SerializeField] private TunalContext context;
private TimeSystem clock;
public string Readout { get; private set; }
private void OnEnable()
{
if (context == null) return;
context.onInitialized.AddListener(Bind);
if (context.IsInitialized) Bind();
}
private void OnDisable()
{
if (context != null) context.onInitialized.RemoveListener(Bind);
if (clock != null) clock.onDisplayTimeUpdate.RemoveListener(UpdateReadout);
clock = null;
}
private void Bind()
{
if (clock != null) clock.onDisplayTimeUpdate.RemoveListener(UpdateReadout);
clock = context.Time;
if (clock == null) return;
clock.onDisplayTimeUpdate.AddListener(UpdateReadout);
UpdateReadout(clock.DisplayTime);
}
private void UpdateReadout(DisplayTimeData value)
{
Readout = $"{value.Hour:00}:{value.Minute:00}:{value.Second:00}";
}
}
}
Subscribe on enable, unsubscribe on disable, and query initial state after binding. For a changing selected context, explicitly detach from the old publisher and bind the new one; the UI binding example demonstrates selection handling. Do not rely on a late subscriber receiving an already-fired initialization event.
Frame and lifecycle ordering¶
TunalContext has early execution order −10000: discovery in Awake, initialization in Start. Time advances/publishes during its own update; Astronomy defers requested evaluation to LateUpdate. Seasons also reconciles in LateUpdate, and phase/lunar state responds through its dependency subscriptions. Supplied reactive responses run at order 5000; lifecycle progression runs at 5100.
These facts do not establish an ordering guarantee between every ordinary script with the same/default execution order. If your integration needs a particular downstream value, subscribe to that system's state event or coordinate a deliberate refresh after changing prerequisites. A clock callback alone is not proof that solar position, presentation, and all lifecycles are final for the frame.
Skips, rewinds, and loads¶
Time ticks report final boundary changes rather than every skipped minute/hour/day. Rewinding a clock does not undo arbitrary side effects of listeners. Lifecycle historical replay is a component-specific state reconstruction, not a world event replay.
Restore has preflight and ordered application, not total listener suppression. Treat load/reconciliation notifications as final-state synchronization opportunities, not evidence that newly observing a stage should grant a reward again. Keep your own “loading” gate where irreversible gameplay listeners need one.
Persistent Inspector callbacks also require valid target objects and method signatures. The reported demo binding issues are validation items, not reasons to rename public events or clear all saved callbacks.