Enzisoft

NZCore Timeline

NZCore timeline

Freecom.enzisoft.timelinev1.0.0

com.enzisoft.timeline

A Unity Timeline editor built with UI Toolkit that you can place inside your own editor windows.

Unity's Timeline window is a separate IMGUI EditorWindow. You can't dock it inside your own tool, restyle it or drive it from your own selection. TimelineMain is a VisualElement that edits the same data, a regular TimelineAsset with its TrackAssets, TimelineClips and PlayableAssets. Put it in a window next to a graph, an inspector and a character preview, and authors can edit timing without switching windows.

Why use it

  • It's a VisualElement. Add it from UXML or code, lay it out with flexbox and restyle it with USS (Authoring/Timeline/Timeline.uss).
  • The data stays standard Timeline data. No custom format. What you author here is a TimelineAsset that Unity's Timeline window can open, a PlayableDirector can play and the Timeline API can read.
  • It reuses Timeline's editor code. Track colors and icons come from [TrackColor] and your TrackEditors, the clip color strip from your ClipEditors. A selected clip shows Unity's own clip inspector: timing, blends, extrapolation and the clip asset's fields.
  • Your asset owns the timeline. The TimelineAsset is stored as a sub-asset of your own asset, so there's no separate timeline file to manage.

Requirements

  • Unity 6 or newer
  • com.unity.timeline and com.unity.entities
  • com.enzisoft.nzcore, which provides PreviewWindow and InspectorView (NZCore.UI.Editor) and the split views the layout uses

The timeline UI is in the NZCore.Timeline.Authoring assembly, which only compiles in the Editor.

Adding the timeline to a window

Place the timeline and a preview in your UXML:

<ui:UXML xmlns:ui="UnityEngine.UIElements">
    <NZCore.UI.Editor.PreviewWindow name="preview-window" />
    <NZCore.UI.Editor.InspectorView name="inspector" />
    <NZCore.Timeline.Authoring.TimelineMain name="timeline" />
</ui:UXML>

Then connect them in your window and hand the timeline your asset:

using NZCore.Timeline.Authoring;
using NZCore.UI.Editor;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

public class AbilityEditorWindow : EditorWindow
{
    [SerializeField] private VisualTreeAsset _layout;
    private TimelineMain _timeline;

    public void CreateGUI()
    {
        _layout.CloneTree(rootVisualElement);

        _timeline = rootVisualElement.Q<TimelineMain>("timeline");
        _timeline.SetPreviewWindow(rootVisualElement.Q<PreviewWindow>("preview-window"));
        _timeline.SetInspectorWindow(rootVisualElement.Q<InspectorView>("inspector")); // optional
    }

    public void Open(AbilityAsset asset)
    {
        _timeline.SetMainAsset(asset);
    }
}
  • SetPreviewWindow is required. Scrubbing evaluates the timeline through the preview.
  • SetInspectorWindow is optional. The selected clip's inspector is also shown there, in addition to Unity's Inspector window.
  • SetMainAsset(ScriptableObject) uses the TimelineAsset sub-asset of the given asset, or creates one named timeline if there is none. It waits for the timeline's first layout before showing the tracks.
  • SetTimelineAsset(TimelineAsset) shows an existing timeline directly. Call it only after the first layout (ZoomableArea.InitDone).

Window > Example TimelineV2 opens a bare TimelineMain in a window for a quick look at the layout.

Preview

Pick a GameObject with an Animator and an Avatar in the preview's Preview Object field. The timeline builds a PlayableGraph from the TimelineAsset on that object, binds animation outputs to its Animator and evaluates the graph whenever the playhead moves. Until a preview object is set, the playhead moves but nothing is evaluated.

Making tracks and clips available

The + menu and the track menus don't list every Timeline type in the project, only types marked with these interfaces:

  • Tracks: non-abstract TrackAsset subclasses that implement IDOTSTrackBase. Derive from DOTSTrack<T>, or implement IDOTSTrack<T> on a subclass of an existing track such as AnimationTrack or AudioTrack. The menu shows the [DisplayName] attribute (System.ComponentModel) if present, otherwise the class name.
  • Clips: PlayableAsset types that implement IDOTSClipBase, for example DOTSClip<T> subclasses. Right-clicking a track lane lists them. Which clips a track accepts is still decided by Timeline's [TrackClipType]; choosing one the track doesn't accept logs a warning. Clip types derived from AnimationPlayableAsset appear as Add from AnimationClip and open the object picker.
using System.ComponentModel;
using NZCore.Timeline.Authoring;
using NZCore.Timeline.Data;
using UnityEngine;
using UnityEngine.Timeline;

public struct EffectClipData : ITimelineClipData { }

[DisplayName("Effects")]
[TrackColor(0.2f, 0.6f, 0.9f)]
[TrackClipType(typeof(EffectClip))]
public class EffectTrack : DOTSTrack<EffectClipData> { }

public class EffectClip : DOTSClip<EffectClipData>
{
    public override byte TimelineClipId => 1; // written to the baked clip as its type ID

    public GameObject Prefab;
}

For a custom track icon or color logic, write a [CustomTimelineEditor] TrackEditor and return them from GetTrackOptions. The clip color strip uses ClipEditor.GetClipOptions(clip).highlightColor. Both are the same editors Unity's Timeline window uses.

Clip visualizers

To draw something in the preview while a clip is active, return a ScriptPlayable of a ClipVisualizerBase subclass from the clip's CreatePlayable. Its OnUpdate(playable) runs on every Editor update while the clip is playing in the preview graph, and can add gizmos to PreviewWindow.DeferredGizmos.

Editing

  • Playhead: click or drag the ruler.
  • Move a clip: drag it. The start snaps to whole frames.
  • Trim a clip: drag its left or right edge. As in Unity's Timeline window, Shift changes whether trimming the start also changes the clip's speed.
  • Zoom: mouse wheel over the clip area zooms around the cursor. The slider at the bottom pans and zooms.
  • Select: click a clip to show it in the Inspector, click a track header to select its TrackAsset.
  • Context menus: right-click a track header, or click its menu button, to delete the track or add a new one. Right-click a clip to delete it. Right-click a track lane to add a clip.
  • Toolbar: first frame, previous frame, play, next frame, last frame, loop, and the current frame number. Type a frame number and leave the field to jump to it.

Playback advances one frame at a time at 60 fps and stops at the end of the timeline, or starts over if loop is on.

Limitations

  • One timeline at a time. Tracks and clips reach the timeline through the static TimelineMain.Instance, which is the most recently created TimelineMain.
  • Fixed 60 fps frame grid and playback.
  • No Undo. Adding or deleting tracks and clips saves the assets immediately. Moving and trimming change the TimelineClip in memory without marking anything dirty, so your window has to mark the asset dirty and save it.
  • Only animation outputs are bound in the preview graph. Other outputs are evaluated without a binding.

Also in this package

Besides the editor, the package can bake timelines into entities: PlayableDirectorBaker<T>, NZPlayableDirector and the BakeTrack/BakeBlob methods of DOTSTrack<T> and DOTSClip<T> convert tracks and clips into clip entities and blob data, and the systems in NZCore.Timeline.Systems update their timers, local time and weights at runtime. The editor doesn't need this; implementing the interfaces is enough to make your types show up in the menus.