# Time Fracture — Script Reference
Start with [[00-Start-Here]] and [[TimeFracture-Getting-Started]] if you are new to the package.
Time control for Unity 6 Timeline. Each `PlayableDirector` gets a **Time Channel** that can play it forward, rewind it, change its speed, freeze it, skip, loop, or remix it into playlists. Any number of channels run at the same time, and named groups let you bend time for many objects at once.
| Script | Folder | Type | Role |
|---|---|---|---|
| TimeChannel | Runtime | MonoBehaviour | Drives one PlayableDirector |
| TimeWorld | Runtime | Static class | Groups, world scale, flags, command routing |
| TimeTypes | Runtime | Data types | Segments, playlists, event info, enums |
| TimeCommand | Runtime | Serializable class | One time instruction |
| TimeCommandTrigger | Runtime | MonoBehaviour | Interaction: runs commands on game events |
| TimeEventMarker | Runtime | Timeline Marker | Fires events and commands as time passes |
| TimeSegmentMarker | Runtime | Timeline Marker | Names a segment in the Timeline window |
| TimeChannelDebugHUD | Runtime | MonoBehaviour | On-screen readout with keyboard controls |
| TimeChannelEditor | Editor | Custom Inspector | Play-mode controls for a channel |
| TimeCommandDrawer | Editor | Property Drawer | Shows only the fields each command uses |
| TimeFractureDemoBuilder | Editor | Menu tool | Builds a demo scene |
---
## Runtime
### TimeChannel.cs
**Type:** MonoBehaviour · **Add to:** any GameObject that has a `PlayableDirector`
This is the core of the system. It switches its director to **Manual** update mode and moves the playhead itself every frame, then evaluates the Timeline. That lets it do things Timeline can't do on its own:
- **Speed and direction:** `SetRate`, `EaseRate` and `Reverse`. A negative rate rewinds.
- **Freeze:** `Freeze`, `Unfreeze` and `FreezeFor(seconds)`.
- **Skip:** `JumpTo(time)`, `JumpToSegment(name)` and `Skip(seconds)`. Skip follows loops and playlists as if that time had actually played.
- **Loop:** `LoopSegment`, `LoopCurrent` and `SetLoopRegion`. Each takes a repeat count, where −1 means loop until `BreakLoop()` is called.
- **Remix:** `PlaySegment`, `PlaySegments("C","A","B")`, `PlayPlaylist`, `ShufflePlaylist` and `ReversePlaylist`. If time is rewound during a playlist, it plays back through the steps in reverse order.
- **End behaviour:** when no playlist is running, the channel can Hold, Loop or PingPong at the ends of the timeline.
- **Markers:** it scans the timeline for Time Event markers, Segment markers and Signal Emitters. As the playhead crosses them in either direction, it fires them through UnityEvents, C# events and `TimeWorld.AnyEvent`.
- **Detached:** keeps time running but stops the Timeline posing its objects and firing markers. Used by "scripted until disturbed" enemies. A channel with no Timeline still keeps its own rate and freeze state, so it can act as a live object's personal time.
The rate that actually applies is the channel's rate × the scale of each of its groups × the world scale.
```codefile Runtime/TimeChannel.cs
```
### TimeWorld.cs
**Type:** static class (doesn't go on a GameObject)
This is the global hub. Every channel registers here when it's enabled. It holds:
- **Groups:** named time scales with freeze switches, such as "Clocks" or "Enemies". `SetGroupScale`, `FreezeGroup` and `FreezeGroupFor` affect every channel in the group.
- **World:** `WorldScale` and `WorldFrozen` affect everything.
- **Story flags:** `SetFlag`, `GetFlag`, `ToggleFlag` and the `FlagChanged` event. Commands use flags to decide which branch the story takes.
- **Command routing:** `Execute(command, self)` works out whether a command targets Self, a Channel, a Group or the World, and applies it.
- **Lookup:** `Find(id)`, `FindAll(id)` and `InGroup(name)`.
It resets itself when you enter Play Mode, even if domain reload is turned off.
```codefile Runtime/TimeWorld.cs
```
### TimeTypes.cs
**Type:** shared data types
This file holds the plain data classes the other scripts share:
- `TimeSegment`: a named time range (name, start, end).
- `PlaylistStep`: one step of a remix (segment, reverse, speed, repeats, holdAfter).
- `TimePlaylist`: a named list of steps, which can loop. It is copied at runtime, so remixing never changes your inspector data.
- `TimeEventInfo`: what listeners receive when a marker fires (channel, id, time, direction, marker).
- Enums: `EndBehaviour` (Hold, Loop, PingPong) and `EventDirection` (Both, ForwardOnly, ReverseOnly).
```codefile Runtime/TimeTypes.cs
```
### TimeCommand.cs
**Type:** serializable class plus the `TimeAction` and `TimeTarget` enums
A `TimeCommand` is a single instruction you can set up in the Inspector, such as "EaseRate group Clocks to −1" or "JumpToSegment Escape". It has these parts:
- **Action:** transport, speed, freeze, skip, loop, remix, or flag actions.
- **Target:** Self, a Channel (by id), a Group, or the World. When the target is a Group or the World, the rate and freeze actions change that group's or the world's scale instead of each channel.
- **Parameters:** `number`, `ease`, `text`, `count` and `reverse`. Which ones apply depends on the action.
- **Condition:** `onlyIfFlag` and `flagValue`. The command runs only when that flag has the chosen value, which is how branching works.
Time Event markers and Time Command Triggers both use these commands, and you can also run them from code.
```codefile Runtime/TimeCommand.cs
```
### TimeCommandTrigger.cs
**Type:** MonoBehaviour · **Add to:** any GameObject
This is the interaction layer. It runs a list of `TimeCommand`s when one of these happens:
- **Manual:** something calls `Fire()`, such as a UI Button, an Input System action or another script. You can also right-click the component and choose **Fire** while in Play mode.
- **OnStart.**
- **A physics trigger:** OnTriggerEnter or OnTriggerExit, in 3D or 2D, with an optional tag filter.
- **OnTimeEvent:** a Time Event with a given id fires. You can limit it to one channel and one direction.
- **OnFlagChanged:** a story flag changes to a given value.
It also has **Once** and **Cooldown** options, and an `onFired` UnityEvent.
```codefile Runtime/TimeCommandTrigger.cs
```
### TimeEventMarker.cs
**Type:** Timeline Marker · **Add in Timeline:** right-click a track's marker area ▸ Add ▸ Time Fracture ▸ Time Event
A marker that fires when a Time Channel's playhead crosses it. **Fire When** sets whether it fires going forward, backward or both. Each marker has an `eventId` that listeners match on, and it can carry its own list of commands. "Self" in those commands means the channel that crossed the marker. Put a flag condition on a command to branch the story right there on the Timeline.
```codefile Runtime/TimeEventMarker.cs
```
### TimeSegmentMarker.cs
**Type:** Timeline Marker · **Add in Timeline:** Markers lane ▸ Add ▸ Time Fracture ▸ Segment Start
This marker names a story beat directly in the Timeline window. A segment runs from its marker to the next segment marker, or to the end of the timeline. Playlists, loops and jumps refer to segments by name. Segments typed into the channel's **Segments** list take priority over markers that have the same name.
```codefile Runtime/TimeSegmentMarker.cs
```
### TimeChannelDebugHUD.cs
**Type:** MonoBehaviour · **Add to:** any GameObject (for testing)
An on-screen panel that lists every channel's time, rate and state (paused, frozen, looping, hold, playlist step, segment), along with the groups and flags. Keyboard controls act on the selected channel:
| Key | Action |
|---|---|
| Tab | Select the next channel |
| Space | Pause |
| R | Reverse |
| F | Freeze |
| ←/→ | Skip back / forward |
| ↑/↓ | Change the rate |
| L | Loop the current segment |
| B | Break the loop |
| P | Play the first playlist |
| S | Shuffle the playlist |
| 1–9 | Jump to a segment |
| G | Rewind the whole world |
| H | Hide the panel |
It reads the keyboard through the Input System package. These are debug hotkeys, so turn **Keyboard Controls** off when they clash with your game's controls (the tutorial scene does).
```codefile Runtime/TimeChannelDebugHUD.cs
```
---
## Editor
### TimeChannelEditor.cs
**Type:** Custom Inspector for `TimeChannel`
Outside Play mode, it warns you if the director has no Timeline, and it has a button that lists all the segments and markers it finds in the Console. During Play mode, it shows the channel's live time, rate and state, a scrub slider, and buttons for Pause, Reverse, Freeze, Restart, Skip, Set Rate and Ease, the loop controls, a row for each segment (Jump, Play, Reverse, Loop), and each playlist (with Shuffle, Flip and Stop).
```codefile Editor/TimeChannelEditor.cs
```
### TimeCommandDrawer.cs
**Type:** Property Drawer for `TimeCommand`
This makes command lists easier to read in the Inspector. Each command collapses to a one-line summary, such as `EaseRate -> Group 'Clocks' (if Paradox)`. When expanded, it shows only the fields that action uses, labelled for what they mean (Rate, Seconds, Segment, Repeats and so on). The flag condition sits on a single line.
```codefile Editor/TimeCommandDrawer.cs
```
### TimeFractureDemoBuilder.cs
**Type:** Editor menu tool · **Menu:** Tools ▸ Time Fracture ▸ Build Demo Scene
Builds `Assets/TimeFractureDemo` with three objects, each playing its own Timeline at the same time:
- **Walker:** its story is split into the segments Enter, Middle and Exit. It has a Halfway event, a "Paradox" branch marker, and a Remix playlist.
- **Clock:** loops, and is in the Clocks group.
- **Pulse:** ping-pongs, and is in the Clocks group.
It also adds trigger rules: passing Halfway freezes the Clocks for 1.5 seconds, and a manual Paradox trigger sets a flag and slows the Story group. Finally, it adds the debug HUD.
```codefile Editor/TimeFractureDemoBuilder.cs
```
---
## Added for the Wiring Scenarios tutorial
See [[TimeFracture-Tutorial-Wiring]] for how these are wired together.
### TimeInteractable.cs
**Type:** MonoBehaviour · **Add to:** any object on a Timeline that has a collider
Turns touch, shot, block and custom events into time commands for the object's Timeline ("Self"). Each reaction can also run a second set of commands a few seconds later, which makes an effect temporary, and can flash a colour.
```codefile Runtime/Interaction/TimeInteractable.cs
```
### TimeBlockSensor.cs
**Type:** MonoBehaviour · **Add to:** a child trigger collider
Reports BlockStart when the first blocker enters and BlockEnd when the last one leaves.
```codefile Runtime/Interaction/TimeBlockSensor.cs
```
### TimeProjectile.cs
**Type:** MonoBehaviour · **Add to:** a projectile prefab, or let TimeShooter build one
Carries a charge word such as Freeze or Rewind, and calls `Shoot(charge)` on the TimeInteractable it hits.
```codefile Runtime/Interaction/TimeProjectile.cs
```
### TimeShooter.cs
**Type:** MonoBehaviour · **Add to:** the player
Fires charged shots, aimed at the pointer, the gamepad right stick or the facing direction. Its controls are Input Actions: Fire, Fire Forward, Next Charge and Aim Stick. It records its shots on the TimeRecorder and replays them when it's on an echo.
```codefile Runtime/Interaction/TimeShooter.cs
```
### TimeVisualTheme.cs
**Type:** ScriptableObject · **Create:** Time Fracture ▸ Visual Theme
A reusable look for one family of Timelines: lens layer, tint, alpha, override material, time-state tints, and ghost settings.
```codefile Runtime/Visuals/TimeVisualTheme.cs
```
### TimeVisualizer.cs
**Type:** MonoBehaviour · **Add to:** the object with the TimeChannel
Applies the theme to all child renderers (and, optionally, to the channel's TimeMembers). It shows the time state as a colour, plays hit flashes, and handles lens visibility, including turning colliders off for hidden layers.
```codefile Runtime/Visuals/TimeVisualizer.cs
```
### TimeLensController.cs
**Type:** MonoBehaviour · **Add to:** one object in the scene
Base rules and switchable lenses that show, ghost or hide each lens layer, with a screen tint and an optional world slow-down. Each lens has its own Toggle input action.
```codefile Runtime/Visuals/TimeLensController.cs
```
### TimeMember.cs
**Type:** MonoBehaviour · **Add to:** any object that should follow a channel's or group's time
Links the object to a channel (by parent, reference or id) or to a group. It provides `DeltaTime` and `LocalTime`, and can drive Animator and particle speed and audio pitch.
```codefile Runtime/Members/TimeMember.cs
```
### TimeOscillator.cs
**Type:** MonoBehaviour (example)
Motion calculated from `TimeMember.LocalTime`, so it rewinds without being recorded.
```codefile Runtime/Members/TimeOscillator.cs
```
### TimeTake.cs
**Type:** data classes
A recorded run: pose and action samples stamped with clock time. Also defines `ITimeEchoActionReceiver`.
```codefile Runtime/Recording/TimeTake.cs
```
### TimeRecorder.cs
**Type:** MonoBehaviour · **Add to:** the player
Records against a clock channel and commits a take to an echo each loop. If time is rewound and play continues, it overwrites the recording from that point, and it can rewind the player along their own path.
```codefile Runtime/Recording/TimeRecorder.cs
```
### TimeEcho.cs
**Type:** MonoBehaviour · **Spawned by:** TimeRecorder
Replays a take in sync with the clock and replays recorded actions to receivers.
```codefile Runtime/Recording/TimeEcho.cs
```
### TimeInput.cs
**Type:** static helpers (`TimeInput`, `TimeTags`)
Input System helpers: default actions with keyboard, mouse and gamepad bindings, safe enable and disable for `InputActionProperty` fields, and pointer aiming. Also comma-separated tag matching.
```codefile Runtime/Util/TimeInput.cs
```
### TimeRewindKey.cs
**Type:** MonoBehaviour
Hold the Rewind action (R or the left trigger) to rewind the world or one group.
```codefile Runtime/Util/TimeRewindKey.cs
```
### TimeDemoPlayer2D.cs / TimeDemoHelp.cs
**Type:** MonoBehaviour (demo)
A minimal platformer controller (Move and Jump input actions) and on-screen instructions (a Toggle action on F1 or Select) for the tutorial scene.
```codefile Runtime/Demo/TimeDemoPlayer2D.cs
```
```codefile Runtime/Demo/TimeDemoHelp.cs
```
### TimeFractureTutorialBuilder.cs
**Type:** Editor menu tool · **Menu:** Tools ▸ Time Fracture ▸ Build Tutorial Scene (2D)
Builds the 2D tutorial level with every scenario wired.
```codefile Editor/TimeFractureTutorialBuilder.cs
```
---
## Added for the Rewindable Enemies tutorial
See [[TimeFracture-Tutorial-Enemies]].
### TimeRewindable.cs
**Type:** MonoBehaviour · **Add to:** AI enemies, physics props, bullets
Gives a live object its own clock, driven by its channel, a time source or the level clock. While that clock runs forward the object records its pose, velocity, alive state and ITimeStateful data; while it runs backward the recording plays back. When time goes forward again, the object continues live from the restored state. It also supports Scripted Until Disturbed enemies, `Kill()` instead of Destroy, linked spawns such as bullets, and loop resets.
```codefile Runtime/Rewind/TimeRewindable.cs
```
### ITimeStateful.cs
**Type:** interface + `TimeRewindSample` data class
Implement `CaptureState()` and `RestoreState()` to make a script's variables (health, ammo, AI state) rewind.
```codefile Runtime/Rewind/ITimeStateful.cs
```
### TimeDemoGuard2D.cs
**Type:** MonoBehaviour (demo)
An example rewind-friendly enemy. It patrols on a Timeline or stands as a sentry, notices the player or echoes, chases, fires linked bullets, takes Strike damage, and dies with `Kill()`.
```codefile Runtime/Demo/TimeDemoGuard2D.cs
```
### TimeDemoBullet2D.cs
**Type:** MonoBehaviour (demo)
A bullet that moves on its owner's time and saves its age. Hitting the player triggers an auto-rewind.
```codefile Runtime/Demo/TimeDemoBullet2D.cs
```
### TimeAutoRewind.cs
**Type:** MonoBehaviour (demo)
Call `TimeAutoRewind.Trigger()` and the world eases into reverse for a moment ("getting hit rewinds time").
```codefile Runtime/Demo/TimeAutoRewind.cs
```
### TimeFractureEnemyDemoBuilder.cs
**Type:** Editor menu tool · **Menu:** Tools ▸ Time Fracture ▸ Build Enemy Rewind Demo (2D)
Builds the enemy arena: a patrol guard, a sentry, a physics crate, a 20-second loop and auto-rewind.
```codefile Editor/TimeFractureEnemyDemoBuilder.cs
```