Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Weird animation when blending timeline clips in runtime

Discussion in 'Timeline' started by ArchSantaZ, Oct 4, 2019.

  1. ArchSantaZ

    ArchSantaZ

    Joined:
    Oct 4, 2019
    Posts:
    3
    Hi,

    I need to create a timeline which contains a track with multiple animation clips in runtime.
    It works pretty well in most cases.

    But in some cases when I try to blend animations(timeline clips) together using this code:

    Code (CSharp):
    1.  
    2. float blendDuration = Mathf.Min((float)timelineClip.duration, config.easeInDuration);
    3. clipCaches[i - 1].duration += blendDuration;
    4. clipCaches[i - 1].blendOutDuration = blendDuration;
    5. timelineClip.blendInDuration = blendDuration;
    6.  
    And then rebuild the graph using

    Code (CSharp):
    1. playableDirector.RebuildGraph();
    The result timeline will look like this:
    timeline_incorrect_mark.jpg

    As you can see, the blending is kinda weird and this makes the result animation glitchy too

    However, if I keep the Timeline window open when I generate the timeline from the code... surprisingly, it works as expected!

    timeline_correct.PNG

    Not sure if I missed something when I generated the timeline or do I need to rebuild it in some specific way?

    Thanks
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,007
    The editor does some extra things that aren't explicit in the API. Calculating blends and extrapolations are the two most prominent.

    You may need to do to force update the blend curves by doing.

    blendInClip.mixInCurve = null;
    blendOutClip.mixOutCurve = null;

    And possibly use TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved); to get the right evaluation in the editor if it's open.
     
  3. ArchSantaZ

    ArchSantaZ

    Joined:
    Oct 4, 2019
    Posts:
    3
    Thank you for the advice.
    I tried resetting the mix curves as you suggested but it still doesn't fix the issue.

    And I cannot use TimelineEditor.Refresh because I need to call it in runtime not in the editor.


    For more details,
    I currently re-use the TimelineClips in each track in the timeline for performance. Not sure if this causes the issue though.

    Code (CSharp):
    1.  
    2. timelineClip = clipCaches[cacheIndex];
    3. var animPlayableAsset = ((AnimationPlayableAsset)timelineClip.asset);
    4. animPlayableAsset.clip = clipMap.clip;
    5. timelineClip.easeInDuration = 0;
    6. timelineClip.easeOutDuration = 0;
    7. timelineClip.blendInDuration = 0;
    8. timelineClip.blendOutDuration = 0;
    9. timelineClip.start = 0;
    10. timelineClip.timeScale = 1;
    11.  
    When each clip is created (using track.CreateClip), it will be stored in the cache list.
    If we need to change animation of the clip, it will look for a timeline clip in the cache list first and then reuse it.
    We cannot use track.CreateClip every time because it takes too much time to perform.

    Do you have any suggestion on this?
     
  4. ArchSantaZ

    ArchSantaZ

    Joined:
    Oct 4, 2019
    Posts:
    3
    I think I solve it!
    It caused by the duration of the clips were incorrectly calculated by myself.
    the duration of the first clip was too long for blending... so the result became a weird animation.
    (actually from the line "clipCaches[i - 1].duration += blendDuration;" which means the clip duration will get longer and longer after reused)

    So when I open the timeline window, the wrong duration get fixed by the editor, I guess.

    Sorry for taking your time seant :(
    Really appreciate your help.
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,007
    Ah great! I'm happy it's working now.