Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

TimelineEditor: TrackAsset.Curves not dispalyed in inline curve editor

Discussion in 'Timeline' started by BaobabStudios, Mar 23, 2020.

  1. BaobabStudios

    BaobabStudios

    Joined:
    Aug 10, 2017
    Posts:
    3
    Hi,

    we have a custom track which animates gameobject properties from the track mixer, with a animation clip playable.

    Code (CSharp):
    1.    
    2.         public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    3.         {
    4.             // Get track binding
    5.             var director = go.GetComponent<PlayableDirector>();
    6.             if (!director) return  base.CreateTrackMixer(graph, go, inputCount);
    7.        
    8.             m_LayerEvaluator = (QuillLayerEvaluator) director.GetGenericBinding(this);
    9.             // Create an AnimationClipPlayable to play layer animation.
    10.             if (hasCurves) curves.legacy = false;
    11.             var animationPlayable = AnimationClipPlayable.Create(graph, curves);
    12.             var animationOutput = AnimationPlayableOutput.Create(graph, "LayerAnimation", m_LayerEvaluator.layerAnimator);
    13.             animationOutput.SetSourcePlayable(animationPlayable);
    14.        
    15.             animationPlayable.SetAnimatedProperties(curves);
    16.             return animationPlayable;
    17.         }
    The track curves are set from another script when the track is created.
    It works as I expected but I have not been able to make the curves show up in the inline curve editor. The track doesn't draw dots for the keyframes either. Is there some interface i need to implement for them to show up?

    Annotation 2020-03-22 173234.png

    I chose to write my own custom track instead of using Animation Track because I need the track to be a special type to be found by other tools. If this is not the right direction, is there a better way of creating my own custom animation track?

    Thanks
     
    Last edited: Mar 23, 2020
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,194
    The Timeline Editor UI does not show arbitrary values of the TrackAsset.curves property, although, it would be a nice addition if it did.

    The UI will display animated track mixer properties, similar to animated clip fields. For example, the following class will display fieldA and fieldB in the UI.

    Code (CSharp):
    1. public class MyTrackAsset : TrackAsset
    2. {
    3.     [Serializable]
    4.     public class MyTrackMixer : PlayableBehaviour
    5.     {
    6.         public Vector3 fieldA;  // these will show up in the editor inline curves
    7.         public float fieldB;
    8.         ...
    9.     }
    10.  
    11.     // this is required so the timeline editor can get serialized properties to animate
    12.     public MyTrackMixer template = new MyTrackMixer();
    13.    
    14.     public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    15.     {
    16.         return ScriptPlayable<MyTrackMixer>.Create(graph, inputCount, template);
    17.     }
    18. ....
    19. }
    It appears that you are trying to replicate the 'infinite track' mode of animation tracks, which unfortunately is a completely custom solution inside of timeline.

    However, if you have a fixed set of properties to animate, then you can use a custom mixer and have your PrepareFrame callback of the track mixer apply the animated values.

    Code (CSharp):
    1.  
    2. public override void ProcessFrame(Playable playable, FrameData info, object userData)
    3. {
    4.      // MyBinding is the type of of the object bound to the track
    5.       ((MyBinding) userData).fieldA = this.fieldA;
    6. }
    I hope that clarifies it somewhat.
     
  3. BaobabStudios

    BaobabStudios

    Joined:
    Aug 10, 2017
    Posts:
    3
    Hi Sean, thank you for your reply. One more question, If I use a custom mixer behaviour, it seems that I will have to add keys for each track manually in the animation window. Is is still possible to procedurally assign animation curves to animate the mixer properties?

    Thanks
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,194
    Yes - use AnimationUtility.GetCurveBindings(track.curves) to see how the EditorCurveBindings are setup. I believe you need to use the type of TrackAsset or PlayableAsset holding the PlayableBehaviour template when creating the EditorCurveBindings.
     
    BaobabStudios likes this.
unityunity