# 7. Timeline Editor Customization Part of [[Timeline Advanced]]. Previous: [[6. Cutscene Controller and Handing Control Back]]. Next: [[8. Worked Example Tests and Pitfalls]]. > [!warning] Code not compiled in Unity > Type-checked against Unity 6000.5.8f1 editor module assemblies and the Timeline **1.8.12** editor assembly (the newest available locally; the 1.8.13 changelog lists bug fixes only, no editor API changes). Not compiled or run in the Editor. Custom tracks are only as good as their authoring experience. Timeline has three editor extension points, all in the `UnityEditor.Timeline` namespace and all registered with `[CustomTimelineEditor(typeof(YourAsset))]`: | Base class | Customizes | Key overrides used here | |---|---|---| | `TrackEditor` | a track type | `GetTrackOptions` (error text, color, icon, min height), `GetBindingFrom` (what a drag-and-drop binds), `IsBindingAssignableFrom`, `OnCreate`, `OnTrackChanged` | | `ClipEditor` | a clip asset type | `OnClipChanged`, `GetClipOptions` (error text, tooltip, name display), `DrawBackground`, `OnCreate`, `GetSubTimelines` | | `MarkerEditor` | a marker type | `GetMarkerOptions` (tooltip, error text), `DrawOverlay`, `OnCreate` | All three are **Editor-only**: put them in an `Editor` folder or in the Editor-only asmdef from the hub. They change the Timeline window, not runtime behaviour. General inspector and window tooling is in [[Custom Inspectors and Editor Tooling]] and [[Editor Windows with UI Toolkit]]; this part is only about the Timeline window. ## 7.1 Track editor: say what is wrong An unbound Light Intensity track silently does nothing. `errorText` puts a warning icon with that message on the track header. ```csharp // Assets/TimelineAdvanced/Editor/LightIntensityTrackEditor.cs // Editor-only: keep it in an Editor folder (or an Editor-only asmdef). using UnityEditor.Timeline; using UnityEngine; using UnityEngine.Timeline; namespace TimelineAdvanced.Editor { [CustomTimelineEditor(typeof(LightIntensityTrack))] public class LightIntensityTrackEditor : TrackEditor { public override TrackDrawOptions GetTrackOptions(TrackAsset track, Object binding) { TrackDrawOptions options = base.GetTrackOptions(track, binding); if (binding == null) options.errorText = "Bind a Light to preview this track."; else if (binding is Light light && light.type == LightType.Directional && light.intensity > 10f) options.errorText = "Directional light above 10: check your physical light units."; return options; } // Accept a dragged GameObject and bind its Light component. public override Object GetBindingFrom(Object candidate, TrackAsset track) { if (candidate is GameObject go && go.TryGetComponent(out Light light)) return light; return base.GetBindingFrom(candidate, track); } } } ``` `GetBindingFrom` means a designer can drag the light's **GameObject** onto the binding slot, not just the Light component. ## 7.2 Clip editor: make the track read like a script `OnClipChanged` runs when a clip, its asset or an animated parameter changes in the editor. The Timeline Text sample uses it to keep `displayName` equal to the text; here the label becomes `Speaker: line`. `GetClipOptions` adds a tooltip and an error when the line is empty or too short to read at the guide speed from part 3. `DrawBackground` tints the clip. ```csharp // Assets/TimelineAdvanced/Editor/SubtitleClipEditor.cs using UnityEditor; using UnityEditor.Timeline; using UnityEngine; using UnityEngine.Timeline; namespace TimelineAdvanced.Editor { [CustomTimelineEditor(typeof(SubtitleClip))] public class SubtitleClipEditor : ClipEditor { static readonly Color k_TooShort = new Color(1f, 0.35f, 0.25f, 0.35f); // Keep the clip label in sync with the text, so the track reads like a script. public override void OnClipChanged(TimelineClip clip) { if (clip.asset is SubtitleClip subtitle && !string.IsNullOrEmpty(subtitle.template.line)) clip.displayName = quot;{subtitle.template.speaker}: {subtitle.template.line}"; } public override ClipDrawOptions GetClipOptions(TimelineClip clip) { ClipDrawOptions options = base.GetClipOptions(clip); if (clip.asset is SubtitleClip subtitle) { options.tooltip = subtitle.template.line; float needed = subtitle.MinimumReadSeconds(); if (string.IsNullOrWhiteSpace(subtitle.template.line)) options.errorText = "Empty subtitle line."; else if (clip.duration < needed) options.errorText = quot;Too short to read: {clip.duration:0.0}s, needs about {needed:0.0}s."; } return options; } // Tint the part of the clip that is shorter than the reading-time guide. public override void DrawBackground(TimelineClip clip, ClipBackgroundRegion region) { base.DrawBackground(clip, region); if (clip.asset is not SubtitleClip subtitle) return; double needed = subtitle.MinimumReadSeconds(); if (clip.duration >= needed || region.endTime <= region.startTime) return; // The region is the visible part of the clip; draw over all of it. EditorGUI.DrawRect(region.position, k_TooShort); } } } ``` `ClipBackgroundRegion.position` is the clip's on-screen rectangle; `startTime` and `endTime` are the visible portion of the clip in clip time, which is why the draw is skipped when they collapse. ## 7.3 Marker editor: show what a skip keeps ```csharp // Assets/TimelineAdvanced/Editor/GameplayEventMarkerEditor.cs using UnityEditor; using UnityEditor.Timeline; using UnityEngine; using UnityEngine.Timeline; namespace TimelineAdvanced.Editor { [CustomTimelineEditor(typeof(GameplayEventMarker))] public class GameplayEventMarkerEditor : MarkerEditor { static readonly Color k_State = new Color(0.3f, 0.9f, 0.4f, 0.5f); static readonly Color k_Cosmetic = new Color(0.9f, 0.6f, 0.2f, 0.5f); public override MarkerDrawOptions GetMarkerOptions(IMarker marker) { MarkerDrawOptions options = base.GetMarkerOptions(marker); if (marker is GameplayEventMarker e) { string kind = e.changesGameState ? "state (fires on skip)" : "cosmetic (dropped on skip)"; options.tooltip = quot;{e.eventId} = {e.value} [{kind}]"; if (string.IsNullOrWhiteSpace(e.eventId)) options.errorText = "Gameplay Event has no eventId."; } return options; } // A thin vertical line through the timeline area, green for state events and // orange for cosmetic ones, so you can see at a glance what a skip will keep. public override void DrawOverlay(IMarker marker, MarkerUIStates uiState, MarkerOverlayRegion region) { if (marker is not GameplayEventMarker e) return; Rect markerRect = region.markerRegion; Rect line = new Rect(markerRect.center.x - 0.5f, region.timelineRegion.y, 1f, region.timelineRegion.height); EditorGUI.DrawRect(line, e.changesGameState ? k_State : k_Cosmetic); } } } ``` The overlay draws a 1 px line through the timeline area at each Gameplay Event: **green** for state events (kept on skip) and **orange** for cosmetic ones (dropped on skip). A designer can see at a glance what pressing Skip at any point will still do. For a fully custom marker *icon*, the Timeline custom marker workflow uses `[CustomStyle("StyleName")]` on the marker class plus a USS file at `Editor/Stylesheets/Extensions/common.uss` (and images under `Editor/Stylesheets/Resources`). That is not repeated here; follow the Notes marker workflow linked below if you want icons. ## 7.4 Checklist for any custom track - A `[DisplayName("Folder/Name")]` so it is grouped in the **+** menu. - `[TrackColor]` distinct from built-in tracks. - A `TrackEditor` error when the binding is missing or wrong. - A `ClipEditor` `displayName` that says what the clip does, not "LightIntensityClip". - `GatherProperties` if the mixer writes serialized component fields (part 2). - A restore path in `OnPlayableDestroy` (parts 2 and 3). ## 7.5 Exercise Give `LightIntensityTrackEditor` an `icon` (a 16x16 `Texture2D` loaded with `EditorGUIUtility.IconContent` or `AssetDatabase.LoadAssetAtPath`) and set `minimumHeight` so the clips are taller. Then add a `ClipEditor` for `LightIntensityClip` that draws the clip's `intensityOverClip` curve in `DrawBackground` with `Handles.DrawAAPolyLine`. ## Sources - `TrackEditor` (Timeline 1.8): https://docs.unity3d.com/Packages/[email protected]/api/UnityEditor.Timeline.TrackEditor.html - `ClipEditor` (Timeline 1.8): https://docs.unity3d.com/Packages/[email protected]/api/UnityEditor.Timeline.ClipEditor.html - `MarkerEditor` (Timeline 1.8): https://docs.unity3d.com/Packages/[email protected]/api/UnityEditor.Timeline.MarkerEditor.html - Create a custom marker (Notes marker, `DrawOverlay`, USS styles): https://docs.unity3d.com/Packages/[email protected]/manual/wf-custom-marker.html - Timeline Customization samples (Text clip editor, Annotation marker editor): https://docs.unity3d.com/Packages/[email protected]/manual/samp-custom-samples.html