Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Runtime created Track fails to play properly - works fine when played from Timeline window

Discussion in 'Animation' started by vonSchlank, Aug 30, 2021.

  1. vonSchlank

    vonSchlank

    Joined:
    Jan 5, 2017
    Posts:
    36
    Hello,

    I made a small test to create a Timeline Track runtime.
    When i have no overlap - meaning no crossfade between clips - it works fine.
    When i set them to overlap, however, creating a crossfade, weird things start to happen.

    If you want to try, package is attached.

    1, Import the Package to an empty project.
    2, Open the scene named TimelineTest.
    3, Enter Play Mode. You should see some grotesque walking animation.
    4, After the animation playback is done, stay in Play Mode and open up a Timeline Window (from menu Window > Sequencing > Timeline)
    5, Click on FemaleDummy in the Hierarchy window. The newly created Track will appear in the Timeline Window.
    6, In the Timeline Window, press the Play button, and see the difference: plays just fine.

    What am i doing wrong? Or is it a bug?
    Tested with 2020.2.3f1, 2020.3.16f1 and 2021.1.17f1

    Thanks in advance!

    (Oh, BTW, If you want to see even weirder things, uncomment line 25 (//clip.start = 0; ) and check the result)

    And if you don't want to import the package:

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEngine.Playables;
    4. using UnityEngine.Timeline;
    5.  
    6. public class TimelineTest : MonoBehaviour
    7. {
    8.     [SerializeField] private List<AnimationClip> animations = new List<AnimationClip>();
    9.     [SerializeField] private Animator animator;
    10.     [SerializeField] private PlayableDirector director;
    11.  
    12.     private void Start()
    13.     {
    14.         TimelineAsset asset = new TimelineAsset();
    15.         director.playableAsset = asset;
    16.         AnimationTrack newTrack = asset.CreateTrack<AnimationTrack>("Test Track");
    17.  
    18.         float start = 0f;
    19.         foreach (var item in animations)
    20.         {
    21.             TimelineClip clip = newTrack.CreateClip(item);
    22.             clip.start = start;
    23.             start += 0.1f;
    24.             //clip.start = 0;
    25.         }
    26.         director.SetGenericBinding(newTrack, animator);
    27.  
    28.         director.Play();
    29.     }
    30. }
     

    Attached Files:

    Last edited: Aug 31, 2021
  2. vonSchlank

    vonSchlank

    Joined:
    Jan 5, 2017
    Posts:
    36
    Solution: clip.blendInDuration or blendOutDuration and blendInCurveMode or blendOutCurveMode must be set properly in order to get the desired result.
    I feel a bit misled by Timeline window, cause anytime i checked on the created track, it showed there is a crossfade. There wasn't, actually... :D
     
    Last edited: Apr 20, 2022