Search Unity

Question Timeline API - Clips mixer sends character upwards when clips are added at runtime via script

Discussion in 'Timeline' started by demzou, Dec 22, 2023.

  1. demzou

    demzou

    Joined:
    Apr 7, 2022
    Posts:
    2
    Hi. I am working on a project that makes use of the timeline API to assemble animation clips at runtime via the UI in the game. I am having a weird bug with the following behaviour:

    In play mode in the editor AND in build mode (MacOS + Windows):
    • Create an animation track attached to the animator of my character
    • Add 2 clips onto an animation track with a 1-second overlap to have a transition with blending
    • Each clip plays well independently, the character moves ok
    • At the time of the transition, the character gets sent into the sky and comes back down to play the second clip
    Buuuuut, if I do the same in play mode in the editor WITH the timeline window open and my timeline asset visible, it works ok. Same if I press play on the button of the timeline panel instead of my play button in the game UI.

    Screen recording of the problem here:




    Unity version: 2022.3.11
    Tested on Mac & PC in Editor and MacOS & Windows after build.

    See below some snippets of how I am using the timeline API to do all of the above:

    Code (CSharp):
    1. // Create animation track
    2. public void createAnimationTrack(string _trackName, Animator bindedAnimator)
    3.     {
    4.         AnimationTrack _theTrack = timeline.CreateTrack<AnimationTrack>(_trackName);
    5.         pl.SetGenericBinding(_theTrack, bindedAnimator);
    6.     }
    7.  
    8. //Add clip
    9.     public void createAnimationClip(string _clipName, AnimationClip _animClip, string _trackName, float _startTime, float _duration)
    10.     {
    11.         foreach (TrackAsset track in timeline.GetOutputTracks())
    12.         {
    13.             if (track.GetType() == typeof(AnimationTrack))
    14.             {
    15.                 if (track.name == _trackName)
    16.                 {
    17.                     AnimationTrack _theTrack = track as AnimationTrack;
    18.                     TimelineClip clip = _theTrack.CreateClip(_animClip);
    19.                     clip.start = _startTime;
    20.                     clip.duration = _duration;
    21.                     clip.displayName = _clipName;
    22.                 }
    23.             }
    24.         }
    25. pl.RebuildGraph();
    26.     }
    27.  
    28. //Play/Stop
    29.     public void playTimeline()
    30.     {
    31.         pl.Play();
    32.     }
    33.     public void stopTimeline()
    34.     {
    35.         pl.Stop();
    36.         pl.DeferredEvaluate();
    37.     }
    Any help would be highly appreciated!!!!
     
    FenyceAssets likes this.