Search Unity

How I can play a timeline in background of another timeline?

Discussion in 'Timeline' started by snoche, Aug 30, 2019.

  1. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    82
    Hi,

    I am using 2 layers of timelines the first one is to control a cinematic animation and the second one is to control the idles one the fist one blends.

    I play the idle playable first and then I play the cinematic timeline, when I have an ease in and out on the cinematic it blends nice with the timeline in background (idle), until here all works fine, but I am trying to change the background idle to a different idle (I have 2 game objects on the scene with 2 playDirectors) and every think I try don't work, as soon I play the changed idle playable it becomes the top animation. Is any way to sort the order of the playables?

    I tried to stop and play the cinematic after but I have other issues with custom tracks so I prefear a way I don't have to stop and play again the animation that already is working.

    What is the best approach to change a playable and keep it on background? is there any method to change the order which will play?

    Thank you,
    David
     
  2. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    The order is based on the order that they are triggered. If you change a timeline in editor, it gets stopped/restarted and will automatically go to the top of the pile.

    The workaround is to call PlayableDirector.RebuildGraph() on all other timelines after making a change to background timeline.

    Alternatively, an animator controller is always on the bottom of the pile. If you use that for a background animation instead of timeline it would work as well.
     
    snoche likes this.
  3. snoche

    snoche

    Joined:
    Feb 22, 2010
    Posts:
    82
    I have a main timeline with a cinematic, and I have signals that change the background timelines at given point, that works fine but I can not make my main cinematic to be on top.

    I have tried RebuildGraph() but unfortunately it crashes every time, maybe because is called from the signal of the graph that needs to be rebuild?

    I tried to store the time, stop and play the main again but then I have problems with the custom dialog track I have as it initializes again. Is there another way I could do that with timelines or I need to use the Animator to have animations in background?
     
  4. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Please file a bug for that. That should work. Signals are designed to send their message outside of the timeline update to avoid that exact type of problem. We would be interested in seeing that crash.

    Back to the ordering issue - there is a workaround you can try. For animation tracks, it's technically not the most recent timeline played that is affecting the animator, but the most recent timeline (i.e. animation track) to be bound to the animator. Playing a timeline creates the graph and binds it, so effectively that's the same thing.

    You can trying rebinding a playing timeline's animators to force a timeline to move to 'on top'.

    Here's a sample of how to do that.

    Code (CSharp):
    1.        static void RebindAnimators(PlayableDirector director)
    2.         {
    3.             if (director == null || !director.playableGraph.IsValid())
    4.                 return;
    5.  
    6.             for (int i = 0; i < director.playableGraph.GetOutputCountByType<AnimationPlayableOutput>(); i++)
    7.             {
    8.                 var animOutput = (AnimationPlayableOutput) director.playableGraph.GetOutputByType<AnimationPlayableOutput>(i);
    9.                 var binding = animOutput.GetTarget();
    10.                 animOutput.SetTarget(null);
    11.                 animOutput.SetTarget(binding);
    12.             }
    13.         }
    14.  
     
    Last edited: Sep 13, 2019