Skip to content

Time and display clocks

TimeSystem owns the clock. Its canonical time representation and its displayed clock are related, but serve different purposes.

Canonical time and display time

Concept Meaning Public API
Canonical day 24 hours and 86,400 canonical seconds CurrentTime, TotalDays
Day position Normalized position in the day NormalizedDayTime
Display clock Canonical day represented with the selected number of hours DisplayTime, DisplayHoursPerDay
Simulated display setting Between 1 and 48 hours per day SetSimulatedHoursPerDay(int)

Changing Hours Per Day changes clock presentation. It does not change the canonical day length or astronomical calculations. System-clock modes display 24 hours.

For a 30-hour display, displayed 15:00 corresponds to canonical 12:00. Use SetDisplayTime for player-facing clock input and canonical APIs when your integration deliberately uses canonical units.

Choose a clock source

  • Simulated advances game-controlled time.
  • System Time reads the local operating-system clock.
  • TimeMode.UTCOffset reads UTC with the configured UTC Offset (Hours).

SetDisplayTime requires Simulated mode. SetPaused changes the pause state only in Simulated mode. If changing clock modes through code, account for the calendar resynchronization requirement; changing the Time System Inspector in Play Mode performs the calendar refresh when it finds one.

Set the simulated rate

Game Minute Duration uses Seconds / Game Minute. SetRealSecondsPerGameMinute(float) selects this rate mode as well as setting its value.

Solar Day Duration uses a physical day length in Earth seconds and a separate time scale:

// After the owning context has initialized, in Simulated mode:
context.Time.ConfigureSolarDay(88775.244, 60f);

This configures a day duration of 88,775.244 Earth seconds accelerated by 60. It does not change display-hour settings. Simulated advancement uses Unity's Time.deltaTime, so Unity's Time.timeScale also applies.

Make deliberate time changes

  • SetDisplayTime(hour, minute, second) changes the displayed time on the current day immediately and cancels an active transition.
  • TransitionToDisplayTime(hour, minute, second, duration) requests a transition on the current day. An earlier target rewinds.
  • Large transitions can snap immediately when their requested pace exceeds Max Visible Days / Sec.

Use the clock recipe for a complete component example.

Listen for state changes

onTimeUpdate publishes canonical time; onDisplayTimeUpdate publishes DisplayTimeData. Display configuration changes also use onDisplayClockChanged.

Ticks do not replay skipped intervals

Simulated minute and hour ticks compare the old and new time positions. A jump across several boundaries reports the final clock state rather than invoking a callback for every intermediate boundary. Day-change publication likewise reports the final day. Do not count these callbacks as an elapsed-time accumulator.

Inspector setup and defaults

Start with the context's Time System. Time Mode selects the source; Start Time initializes Simulated mode (component defaults 06:00:00). Rate Mode selects Game Minute Duration (default) or Solar Day Duration. Seconds / Game Minute defaults to 1 and is clamped to at least 0.001. Solar Day (Seconds) defaults to 86400; Time Scale defaults to 1. Hours Per Day defaults to 24 and is clamped to 1–48. UTC Offset (Hours) is constrained to −12 through +14, including fractional hours.

To configure a 10-minute physical-day playback, keep Simulated mode and call ConfigureSolarDay(86400, 144f): 86,400/144 = 600 real seconds at Unity time scale 1. That does not change the canonical 86,400-second representation. A display “hour” on a 30-hour clock covers 24/30 canonical hours.

Transitions, pauses, and rewinding

Default Duration, Max Visible Days / Sec, and Transition Curve control deliberate transitions, not ordinary clock advancement. The component default duration is 5 seconds and default pace limit is 2 days/second. The limit is configurable: do not hardcode two days/second in integration logic.

TransitionBySeconds, TransitionByMinutes, TransitionByHours, and TransitionByDays use canonical units and accept negative movement. TransitionToElapsedSeconds uses absolute elapsed canonical seconds; TransitionToTotalDays preserves the current time of day. TransitionToTime and TransitionToDisplayTime stay on the current day, so an earlier target rewinds rather than moving forward through tomorrow.

Zero/nonfinite duration or a requested average pace above the configured limit snaps to the target. Animated transitions use unscaled wall-clock seconds, independently of Unity's normal time scale, and resume a paused simulated clock. CancelTransition() cancels the animation without returning to its start. Calendar representability can reject a target. These operations do not rewind arbitrary gameplay side effects triggered by your own listeners.

Event contract and calendar synchronization

Event Payload and intended use
onTimeUpdate Normalized canonical day fraction and TimeData
onMinuteTick, onHourTick Current canonical TimeData when an absolute boundary index changes
onDayChanged Final elapsed-day index, including backward changes
onDisplayTimeUpdate Current DisplayTimeData
onDisplayMinuteTick, onDisplayHourTick Display-clock boundary changes
onDisplayClockChanged Current display clock after display configuration/mode changes

Subscribe during OnEnable and unsubscribe during OnDisable; do not assume a late listener receives historical initial events. Query state immediately after binding when needed. Endpoint ticks are not counts of elapsed minutes. Astronomy and other dependent systems can evaluate later in the frame, so a time callback is not a guarantee that every downstream value has already updated.

SetTimeMode cancels a transition and changes the source. It does not independently reconcile Calendar's anchor. Call context.Calendar.RefreshAfterTimeModeChange() when applicable; the runtime UI controller already coordinates that operation. System modes resynchronize with the operating-system clock rather than replaying an authored simulated clock from a save.

Common mistakes

  • Confusing display hours with physical day duration: configure display and rate separately.
  • Calling simulated setters while System Time is authoritative: select the intended mode deliberately.
  • Expecting pause to freeze system clocks: pause is a simulated-clock setting.
  • Counting tick callbacks to accumulate elapsed time: read chronological state instead.
  • Treating a backward time transition as full gameplay rollback: only consumers with explicit history policies can restore their own earlier state.

Continue reading