Skip to content

Class

GameClock

Generated GDScript class reference for CalendarTime.GameClock.

Status
Current
Version
v2.1.0
Source updated
2026-08-09
Generated on
2026-09-01

GameClock — the runtime clock consumers reference. A self-contained Resource holding the microsecond count, calendar, signal bus, serializer, and age service. date_time() is derived from the count via the calendar, so it is never stored and never stale.

Source: addons/calendar_time/game_time/state/game_clock.gd

Syntax

class GameClock extends Resource

Members

NameKindSummary
ProjectionRangeField`ProjectionRange` is preloaded here to bound safe date projection.
current_microsecondsPropertyThe canonical clock value: an exact integer count of elapsed game-microseconds. Source of truth. Everything else (date_time, game_seconds) is derived from it. Not @export — it's runtime state, not authored data; saves go through TimeSnapshot.
speed_multiplierPropertyAuthoritative per-clock runtime speed multiplier. Applied by `advance_scaled_microseconds()` when TimeHost or ClockGroup drives this clock. This is the only field that affects clock advancement rate. Host-wide rate is `TimeHost.time_scale.delta_multiplier`. Per-clock rate is `GameClock.speed_multiplier`. Final formula: clock_delta = engine_delta × host_multiplier × clock_multiplier. Pause/resume: any value `<= 0.0` pauses this clock. `advance_scaled_microseconds` returns early, so boundary events stop while paused. UI consumers that read `clock.date_time()` are not gated here. Watch `clock_speed_changed` to bridge pause to tweens and animations.
calendarPropertyThe calendar that defines the shape of time (months, days, event days) and the date math + rate (calendar.get_scale()). Authored on the clock resource.
time_scalePropertyPer-clock time scale for animation consumers (flipper, emote bob, etc.). Animation systems poll `clock.time_scale.delta_multiplier` to convert real-time intervals into game-time intervals. This field does NOT affect clock advancement — `advance_scaled_microseconds()` reads `speed_multiplier` only. Leave unset when no per-clock animation consumer needs the rate. TimeHost propagates its own `time_scale` to this field so animation consumers get a consistent rate without each one reaching for the host.
epochPropertyOptional reference date used as the zero-point for date_time derivation. date_time() returns calendar.advance_date_time(epoch, elapsed_seconds). Leave unset to use DateTime.new(), the calendar epoch fallback.
persistent_idPropertyAuthored persistent identity for save/load. Empty by default; resolved lazily via `clock_id`. When non-empty, this is the second-highest-priority source for `clock_id` identity (after `clock_id_override` but before `resource_path` and the runtime counter). Assign once via `assign_persistent_id()` (editor action or script). Leave it stable — changing it silently breaks the link to existing saves. Unlike `resource_path` (which changes on file rename, project restructure, or cross-machine copy), a `persistent_id` is a UUID. It survives renames, restructuring, process restarts, and cross-machine use. Duplicating a resource copies its UUID; duplicate IDs are detected and can be regenerated. `ClockGroupSerializer` stores this alongside `clock_id` in per-clock save entries and detects duplicates within a host's clock group. Runtime-only clocks (no `.tres` file) may call `assign_persistent_id()` for durable persistence across process restarts. Clocks without a `persistent_id` fall back to the documented `clock_id` resolution chain.
clock_id_overridePropertyStable identity for save/load (legacy explicit override). Empty by default; resolved lazily via `clock_id`. Uses resource_path hash when loaded from a file, else a runtime counter. `ClockGroupSerializer` keys per-clock save data by this id, not array index. Two clones of the same `.tres` share an id automatically. Different `.tres` files always differ. Two `GameClock.new()` calls get distinct counter ids. Override `clock_id` for explicit cross-machine identity.
signal_busPropertyThe clock event bus. Created eagerly so a consumer can subscribe the moment it holds the clock — before the host has finished _ready. The clock itself emits all clock-boundary events on this bus from `advance_microseconds`.
age_servicePropertyThe age service bound to this clock's time. Optional. Setter wires `age_service.clock = self` so the counter subscribes to this bus. Not @export — Godot cannot resolve a custom Resource @export here. Assign from the clock `.tres` or at runtime; the setter still wires `clock = self`.
time_snapshot_serializerPropertyThe clock's own time serializer (constructed in _init; self-wired).
age_registryPropertyThe clock's own age registry. Each `GameClock` carries its own `AgeStateRegistry` so age state is hermetically scoped to the clock: `AgeService`s and `AgeComponent`s attached to this clock read/write here. No process singleton — two clocks can run side-by-side without seeing each other's age states. Constructed in `_init`; lifetime matches the clock resource.
clock_idPropertyStable id used by ClockGroupSerializer for save/load identity. Lazy-derives from `clock_id_override` → `persistent_id` → resource_path → a monotonic counter (see `_derive_clock_id` for the exact priority chain). Once resolved, the value is cached — re-deriving only happens if `persistent_id` or `clock_id_override` is reassigned, which clears the cache. Priority chain (issue #424): 1. `clock_id_override` (explicit designer label) — durable across sessions. 2. `persistent_id` (authored UUID) — durable across renames, restarts, machines. 3. `resource_path` hash — durable when the same `.tres` is shipped. 4. Runtime counter — session-local; not durable across process restarts.
assign_persistent_idMethod
regenerate_persistent_idMethod
advance_microsecondsMethod
advance_through_microsecondsMethod
advance_scaled_microsecondsMethod
progress_timeMethod
advance_to_next_dayMethod
publish_current_stateMethod
publish_state_loadedMethod
get_time_snapshot_serializerMethod
to_dictMethod
from_dictMethod
date_timeMethod
game_secondsMethod