Search Unity

Problems Mixing Timeline Playables

Discussion in 'Timeline' started by silkms-bf, Sep 20, 2017.

  1. silkms-bf

    silkms-bf

    Joined:
    Feb 26, 2016
    Posts:
    12
    When trying to blend the weights between two timeline playables only the timeline in the first slot of the AnimationMixerPlayable will play.

    If I fill the second slot of the animation mixer with an AnimationClipPlayable, the timeline and animation will correctly blend.

    As soon as I switch the slots of the timeline and animation in the mixer, so that the timeline is in the second slot. The animation in the timeline no longer affects the character.

    Essentially what I have seen is that anytime a timeline is connected to an animation mixer's second slot, it won't affect the character.

    The code below illustrates the broken case. Swapping the index of the timeline Playable and the AnimationClipPlayable in the mixer allows them to crossfade correctly.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Playables;
    3. using UnityEngine.Animations;
    4. using UnityEngine.Timeline;
    5.  
    6. public class AnimationController_Test_Example : MonoBehaviour
    7. {
    8.     public float weight;
    9.  
    10.     // Animation clip to play
    11.     public AnimationClip clip;
    12.     // Timeline to play
    13.     public TimelineAsset timeline;
    14.  
    15.     PlayableGraph m_PlayableGraph;
    16.     AnimationMixerPlayable m_Mixer;
    17.  
    18.  
    19.     void Start()
    20.     {
    21.         m_PlayableGraph = PlayableGraph.Create();
    22.  
    23.         // Create a playable asset frome the timeline.
    24.         Playable timelinePlayable = timeline.CreatePlayable(m_PlayableGraph, gameObject);
    25.  
    26.         // Get the animation output that is generated from the timeline playable and set it's target to our animator.
    27.         AnimationPlayableOutput playableOutput = (AnimationPlayableOutput)m_PlayableGraph.GetOutputByType<AnimationPlayableOutput>(0);
    28.         playableOutput.SetTarget(GetComponent<Animator>());
    29.  
    30.  
    31.         // Create an animation clip playable.
    32.         AnimationClipPlayable animPlayable = AnimationClipPlayable.Create(m_PlayableGraph, clip);
    33.  
    34.         // Create an animation mixer with 2 inputs
    35.         m_Mixer = AnimationMixerPlayable.Create(m_PlayableGraph, 2);
    36.  
    37.         // Connect the timeline playable and animation clip playable to the anim mixer
    38.         // BUG ??? When assigning the timelinePlayable to the second slot (index 1) the timeline does not affect the player.
    39.         // If the timelinePlayable is assigned to the first slot (index 0) then the 2 playbles mix as expected.
    40.         m_Mixer.ConnectInput(0, animPlayable, 0);
    41.         m_Mixer.ConnectInput(1, timelinePlayable, 0);
    42.  
    43.         // Set the mixer as the playable output's source.
    44.         playableOutput.SetSourcePlayable(m_Mixer);
    45.  
    46.         // Play the graph.
    47.         m_PlayableGraph.Play();
    48.  
    49. #if UNITY_EDITOR
    50.         GraphVisualizerClient.Show(m_PlayableGraph, name + " (Anim Controller)");
    51. #endif
    52.     }
    53.  
    54.     void Update()
    55.     {
    56.         weight = Mathf.Clamp01(weight);
    57.  
    58.         m_Mixer.SetInputWeight(0, 1.0f - weight);
    59.         m_Mixer.SetInputWeight(1, weight);
    60.     }
    61. }
    62.  
    The playable graph for each scenario shows the following.



    Is this a bug or am I using the Playables/Timeline API incorrectly?

    Thanks!
     
    Last edited: Sep 20, 2017
    tarahugger and mathiastg like this.
  2. silkms-bf

    silkms-bf

    Joined:
    Feb 26, 2016
    Posts:
    12
    Bump: Updated the description and added an image of the playable graph visualizer.
     
  3. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Hmm.. I think this is a bug. There is an assumption in Timeline that the subgraph attached to the output isn't changed, and there is some processing happening on it, which may explain the behaviour you are seeing.
     
  4. silkms-bf

    silkms-bf

    Joined:
    Feb 26, 2016
    Posts:
    12
    @seant_unity thanks for the response! Any chance that there is a work around or fix planned in the near future?
     
  5. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Good question. There is a some work being done right now that may have an impact on that behaviour, but it's still in progress, and I don't think there will be a fix in near future.

    I would recommend filing a bug.

    As for workarounds, it really depends on what you are trying to do. The animator plays all outputs 'stacked', so if you play a timeline, then play a custom playable graph (i.e. just the animation clip), you can control the blend between them by the weight of the animation output.

    But your mileage may vary with that approach, as timeline writes to the weight of it's animation outputs. So you can only control your own graphs, not timeline generated one that way.
     
  6. silkms-bf

    silkms-bf

    Joined:
    Feb 26, 2016
    Posts:
    12
    Okay thanks!
     
  7. silkms-bf

    silkms-bf

    Joined:
    Feb 26, 2016
    Posts:
    12
  8. silkms-bf

    silkms-bf

    Joined:
    Feb 26, 2016
    Posts:
    12
    @seant_unity When you refer to the animation outputs as being "stacked", does this mean that each animation output (for a single animator) is adding it's transformations to the previous one?
     
  9. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Not so much added, but blended. The output weight is how much to blended to the previous output. So the animator controller is usually the base, then a timeline will blend on top of that (use ease-in on the first clip). There shouldn't be any reason why hand built graphs can't do the same thing.
     
  10. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    I've got the same issue, when I create a graph and try to blend between two timelines the timeline in the second index appears to be playing but doesn't actually output animation.
     

    Attached Files:

  11. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    here's my code (based on the previous post, but mixing 2 timelines instead of a timeline and a clip)

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Playables;
    5. using UnityEngine.Timeline;
    6. using UnityEngine.Animations;
    7.  
    8. public class AnimationControl : MonoBehaviour
    9. {
    10.     public TimelineAsset timeline1;
    11.     public TimelineAsset timeline2;
    12.  
    13.     public float weight;
    14.  
    15.     PlayableGraph m_PlayableGraph;
    16.     AnimationMixerPlayable m_Mixer;
    17.  
    18.     public Animator anim;
    19.  
    20.  
    21.     void Start()
    22.     {
    23.         m_PlayableGraph = PlayableGraph.Create();
    24.         Debug.Log(m_PlayableGraph.GetOutputCount());
    25.  
    26.         // Create a playable asset frome the timeline.
    27.         Playable timelinePlayable1 = timeline1.CreatePlayable(m_PlayableGraph, gameObject);
    28.         Playable timelinePlayable2 = timeline2.CreatePlayable(m_PlayableGraph, gameObject);
    29.  
    30.         // create an animation output on the graph
    31.         AnimationPlayableOutput.Create(m_PlayableGraph, "Animation", anim);
    32.  
    33.         // Get the animation output that is generated from the timeline playable and set it's target to our animator
    34.         AnimationPlayableOutput playableOutput = (AnimationPlayableOutput)m_PlayableGraph.GetOutputByType<AnimationPlayableOutput>(0);
    35.         playableOutput.SetTarget(anim);
    36.  
    37.         // Create an animation mixer with 2 inputs
    38.         m_Mixer = AnimationMixerPlayable.Create(m_PlayableGraph, 2);
    39.  
    40.         // Connect the timeline playable and animation clip playable to the anim mixer
    41.         // BUG ??? When assigning the timelinePlayable to the second slot (index 1) the timeline does not affect the player.
    42.         // If the timelinePlayable is assigned to the first slot (index 0) then the 2 playbles mix as expected.
    43.         m_Mixer.ConnectInput(0, timelinePlayable1, 0);
    44.         m_Mixer.ConnectInput(1, timelinePlayable2, 0);
    45.  
    46.         // Set the mixer as the playable output's source.
    47.         playableOutput.SetSourcePlayable(m_Mixer);
    48.  
    49.         // Play the graph.
    50.         m_PlayableGraph.Play();
    51.  
    52.         #if UNITY_EDITOR
    53.         GraphVisualizerClient.Show(m_PlayableGraph, name + " (Anim Controller)");
    54.         #endif
    55.     }
    56.  
    57.     void Update()
    58.     {
    59.         weight = Mathf.Clamp01(weight);
    60.  
    61.         m_Mixer.SetInputWeight(0, 1.0f - weight);
    62.         m_Mixer.SetInputWeight(1, weight);
    63.     }
    64. }
    65.  
     
  12. DenverCoulson

    DenverCoulson

    Joined:
    Aug 8, 2012
    Posts:
    9
    Was this bug ever resolved? It shows it's closed but I am using a two timeline solution as well and only one actually outputs.
     
  13. edwon

    edwon

    Joined:
    Apr 24, 2011
    Posts:
    266
    I think this has been resolved in Unity 2018 (which is still in beta) because I know they did a lot of timeline fixes for 2018. But I haven't tested it yet so I don't know.
     
  14. DinosCharmGames

    DinosCharmGames

    Joined:
    May 9, 2018
    Posts:
    25
    We are still getting this in 2018.1 though I see the bug was closed several months ago. Can we get confirmation on what version this fix is supposed to exist in?
     
  15. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    I looked into it, and it appears the fix is in both 2018.2 and 2017.4f2. Mistake on our part, we'll get the fix backported to 2018.1 asap.
     
  16. DinosCharmGames

    DinosCharmGames

    Joined:
    May 9, 2018
    Posts:
    25
    Thanks. That will be a big help. Will that be a patch release for 2018.1 then? Just so we know what to look out for.
     
  17. seant_unity

    seant_unity

    Unity Technologies

    Joined:
    Aug 25, 2015
    Posts:
    1,516
    Yes, it will. The fix is already in the queue, so it should be in one of the next couple patch releases.
     
  18. yunshuijin

    yunshuijin

    Joined:
    Jan 29, 2017
    Posts:
    11
    The animation blending issue is fixed for 2018.2, I've tested blending two timelines which work quite well.
    However, there is an issue there for audio mixer playable. It doesn't work at all for blending several audios regardless of the weight value. Besides, it's very easy to crash when I change the audio playable graph at runtime.
     
  19. jnast

    jnast

    Joined:
    Jul 24, 2018
    Posts:
    1
    Last edited: Aug 22, 2018