Class TrackAsset
A PlayableAsset representing a track inside a timeline.
Inherited Members
Namespace: UnityEngine.Timeline
Assembly: Unity.Timeline.dll
Syntax
[Serializable]
public abstract class TrackAsset : PlayableAsset, IPlayableAsset, ISerializationCallbackReceiver, IPropertyPreview
Remarks
Derive from TrackAsset to implement custom timeline tracks. TrackAsset derived classes support the following attributes: HideInMenuAttribute TrackColorAttribute TrackClipTypeAttribute TrackBindingTypeAttribute DisplayNameAttribute
Examples
Fields
m_Clips
Declaration
[SerializeField]
[HideInInspector]
protected List<TimelineClip> m_Clips
Field Value
Type | Description |
---|---|
List<TimelineClip> |
Properties
curves
An animation clip storing animated properties of the attached PlayableAsset
Declaration
public AnimationClip curves { get; }
Property Value
Type | Description |
---|---|
AnimationClip |
duration
The length, in seconds, of this track
Declaration
public override sealed double duration { get; }
Property Value
Type | Description |
---|---|
double |
Overrides
end
The end time, in seconds, of this track
Declaration
public double end { get; }
Property Value
Type | Description |
---|---|
double |
hasClips
Whether this track contains any TimelineClip.
Declaration
public bool hasClips { get; }
Property Value
Type | Description |
---|---|
bool |
hasCurves
Whether this track contains animated properties for the attached PlayableAsset.
Declaration
public bool hasCurves { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
This property is false if the curves property is null or if it contains no information.
isEmpty
Whether this track is considered empty.
Declaration
public virtual bool isEmpty { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
A track is considered empty when it does not contain a TimelineClip, Marker, or Curve.
isSubTrack
Returns whether this track is a subtrack
Declaration
public bool isSubTrack { get; }
Property Value
Type | Description |
---|---|
bool |
locked
The local locked state of the track.
Declaration
public bool locked { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Note that locking a track only affects operations in the Timeline Editor. It does not prevent other API calls from changing a track or it's clips.
This returns or sets the local locked state of the track. A track may still be locked for editing because one or more of it's parent tracks in the hierarchy is locked. Use lockedInHierarchy to test if a track is locked because of it's own locked state or because of a parent tracks locked state.
lockedInHierarchy
The locked state of a track. (RO)
Declaration
public bool lockedInHierarchy { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Note that locking a track only affects operations in the Timeline Editor. It does not prevent other API calls from changing a track or it's clips.
This indicates whether a track is locked in the Timeline Editor because either it's locked property is enabled or a parent track is locked.
muted
Whether the track is muted or not.
Declaration
public bool muted { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
A muted track is excluded from the generated PlayableGraph
mutedInHierarchy
The muted state of a track.
Declaration
public bool mutedInHierarchy { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
A track is also muted when one of its parent tracks are muted.
outputs
Returns a description of the PlayableOutputs that will be created by this track.
Declaration
public override IEnumerable<PlayableBinding> outputs { get; }
Property Value
Type | Description |
---|---|
IEnumerable<PlayableBinding> |
Overrides
parent
The owner of this track.
Declaration
public PlayableAsset parent { get; }
Property Value
Type | Description |
---|---|
PlayableAsset |
Remarks
If this track is a subtrack, the parent is a TrackAsset. Otherwise the parent is a TimelineAsset.
start
The start time, in seconds, of this track
Declaration
public double start { get; }
Property Value
Type | Description |
---|---|
double |
supportsNotifications
Indicates if a track accepts markers that implement INotification.
Declaration
public bool supportsNotifications { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Only tracks with a bound object of type GameObject or Component can accept notifications.
timelineAsset
The TimelineAsset that this track belongs to.
Declaration
public TimelineAsset timelineAsset { get; }
Property Value
Type | Description |
---|---|
TimelineAsset |
Methods
CalculateItemsHash()
Declaration
protected virtual int CalculateItemsHash()
Returns
Type | Description |
---|---|
int |
CanCreateTrackMixer()
Whether the track can create a mixer for its own contents.
Declaration
public virtual bool CanCreateTrackMixer()
Returns
Type | Description |
---|---|
bool | Returns true if the track's mixer should be included in the playable graph. |
Remarks
A return value of true does not guarantee that the mixer will be included in the playable graph. GroupTracks and muted tracks are never included in the graph
CreateClip<T>()
Creates a clip on the track with a playable asset attached, whose derived type is specified by T
Declaration
public TimelineClip CreateClip<T>() where T : ScriptableObject, IPlayableAsset
Returns
Type | Description |
---|---|
TimelineClip | Returns a TimelineClip whose asset is of type T |
Type Parameters
Name | Description |
---|---|
T | A PlayableAsset derived type |
Remarks
Throws InvalidOperationException if T
is not supported by the track.
Supported types are determined by TrackClip attributes that decorate the TrackAsset derived class
CreateCurves(string)
Creates an AnimationClip to store animated properties for the attached PlayableAsset.
Declaration
public void CreateCurves(string curvesClipName)
Parameters
Type | Name | Description |
---|---|---|
string | curvesClipName | The name of the AnimationClip to create. This method does not ensure unique names. If you want a unique clip name, you must provide one. See ObjectNames.GetUniqueName for information on a method that creates unique names. |
Remarks
If curves already exists for this track, this method produces no result regardless of the value specified for curvesClipName.
CreateDefaultClip()
Creates a TimelineClip on this track.
Declaration
public TimelineClip CreateDefaultClip()
Returns
Type | Description |
---|---|
TimelineClip | Returns a new TimelineClip that is attached to the track. |
Remarks
The type of the playable asset attached to the clip is determined by TrackClip attributes that decorate the TrackAsset derived class
CreateMarker(Type, double)
Creates a marker of the requested type, at a specific time, and adds the marker to the current asset.
Declaration
public IMarker CreateMarker(Type type, double time)
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type of marker. |
double | time | The time where the marker is created. |
Returns
Type | Description |
---|---|
IMarker | Returns the instance of the created marker. |
Remarks
All markers that implement IMarker and inherit from ScriptableObject are supported.
Markers that implement the INotification interface cannot be added to tracks that do not support notifications.
CreateMarker will throw InvalidOperationException with tracks that do not support notifications if type
implements the INotification interface.
See Also
CreateMarker<T>(double)
Creates a marker of the requested type, at a specific time, and adds the marker to the current asset.
Declaration
public T CreateMarker<T>(double time) where T : ScriptableObject, IMarker
Parameters
Type | Name | Description |
---|---|---|
double | time | The time where the marker is created. |
Returns
Type | Description |
---|---|
T | Returns the instance of the created marker. |
Type Parameters
Name | Description |
---|---|
T | The type of marker to create. |
Remarks
All markers that implement IMarker and inherit from ScriptableObject are supported.
CreateMarker will throw InvalidOperationException with tracks that do not support notifications if T
implements the INotification interface.
See Also
CreatePlayable(PlayableGraph, GameObject)
Overrides PlayableAsset.CreatePlayable(). Not used in Timeline.
Declaration
public override sealed Playable CreatePlayable(PlayableGraph graph, GameObject go)
Parameters
Type | Name | Description |
---|---|---|
PlayableGraph | graph | The graph to inject playables into.The game object which initiated the build. |
GameObject | go | The graph to inject playables into.The game object which initiated the build. |
Returns
Type | Description |
---|---|
Playable | The playable injected into the graph, or the root playable if multiple playables are injected. |
Overrides
CreatePlayable(PlayableGraph, GameObject, TimelineClip)
Constructs a Playable from a TimelineClip.
Declaration
protected virtual Playable CreatePlayable(PlayableGraph graph, GameObject gameObject, TimelineClip clip)
Parameters
Type | Name | Description |
---|---|---|
PlayableGraph | graph | PlayableGraph that will own the playable. |
GameObject | gameObject | The GameObject that builds the PlayableGraph. |
TimelineClip | clip | The TimelineClip to construct a playable for. |
Returns
Type | Description |
---|---|
Playable | A playable that will be set as an input to the Track Mixer playable, or Playable.Null if the clip does not have a valid PlayableAsset |
Remarks
By default, this method invokes Playable.CreatePlayable, sets animated properties, and sets the speed of the created playable. Override this method to change this default implementation.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if the specified PlayableGraph is not valid. |
ArgumentNullException | Thrown if the specified TimelineClip is not valid. |
CreateTrackMixer(PlayableGraph, GameObject, int)
Creates a mixer used to blend playables generated by clips on the track.
Declaration
public virtual Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
Parameters
Type | Name | Description |
---|---|---|
PlayableGraph | graph | The graph to inject playables into |
GameObject | go | The GameObject that requested the graph. |
int | inputCount | The number of playables from clips that will be inputs to the returned mixer |
Returns
Type | Description |
---|---|
Playable | A handle to the [[Playable]] representing the mixer. |
Remarks
Override this method to provide a custom playable for mixing clips on a graph.
DeleteClip(TimelineClip)
Delete a clip from this track.
Declaration
public bool DeleteClip(TimelineClip clip)
Parameters
Type | Name | Description |
---|---|---|
TimelineClip | clip | The clip to delete. |
Returns
Type | Description |
---|---|
bool | Returns true if the removal was successful |
Remarks
This method will delete a clip and any assets owned by the clip.
DeleteMarker(IMarker)
Removes a marker from the current asset.
Declaration
public bool DeleteMarker(IMarker marker)
Parameters
Type | Name | Description |
---|---|---|
IMarker | marker | The marker instance to be removed. |
Returns
Type | Description |
---|---|
bool | Returns true if the marker instance was successfully removed. Returns false otherwise. |
GatherProperties(PlayableDirector, IPropertyCollector)
Called by the Timeline Editor to gather properties requiring preview.
Declaration
public virtual void GatherProperties(PlayableDirector director, IPropertyCollector driver)
Parameters
Type | Name | Description |
---|---|---|
PlayableDirector | director | The PlayableDirector invoking the preview |
IPropertyCollector | driver | PropertyCollector used to gather previewable properties |
GetAnimationClipHash(AnimationClip)
Gets the hash code for an AnimationClip.
Declaration
protected static int GetAnimationClipHash(AnimationClip clip)
Parameters
Type | Name | Description |
---|---|---|
AnimationClip | clip | The animation clip. |
Returns
Type | Description |
---|---|
int | A 32-bit signed integer that is the hash code for |
GetChildTracks()
The list of subtracks or child tracks attached to this track.
Declaration
public IEnumerable<TrackAsset> GetChildTracks()
Returns
Type | Description |
---|---|
IEnumerable<TrackAsset> | Returns an enumerable list of child tracks owned directly by this track. |
Remarks
In the case of GroupTracks, this returns all tracks contained in the group. This will return the all subtracks or override tracks, if supported by the track.
GetClips()
A list of clips owned by this track
Declaration
public IEnumerable<TimelineClip> GetClips()
Returns
Type | Description |
---|---|
IEnumerable<TimelineClip> | Returns an enumerable list of clips owned by the track. |
GetMarker(int)
Returns the marker at a given position, on the current asset.
Declaration
public IMarker GetMarker(int idx)
Parameters
Type | Name | Description |
---|---|---|
int | idx | The index of the marker to be returned. |
Returns
Type | Description |
---|---|
IMarker | The marker. |
Remarks
The ordering of the markers is not guaranteed.
GetMarkerCount()
Returns the number of markers on the current asset.
Declaration
public int GetMarkerCount()
Returns
Type | Description |
---|---|
int | The number of markers. |
GetMarkers()
Returns an enumerable list of markers on the current asset.
Declaration
public IEnumerable<IMarker> GetMarkers()
Returns
Type | Description |
---|---|
IEnumerable<IMarker> | The list of markers on the asset. |
OnAfterTrackDeserialize()
Called after a track has been deserialized.
Declaration
protected virtual void OnAfterTrackDeserialize()
OnBeforeTrackSerialize()
Called before a track is serialized.
Declaration
protected virtual void OnBeforeTrackSerialize()
OnCreateClip(TimelineClip)
Called when a clip is created on a track.
Declaration
protected virtual void OnCreateClip(TimelineClip clip)
Parameters
Type | Name | Description |
---|---|---|
TimelineClip | clip | The timeline clip added to this track |
Remarks
Use this method to set default values on a timeline clip, or it's PlayableAsset.