Blend two identical timelines with multiple Animator bindings

Hi everyone

I have been searching the forums for days but though I have come close I still can’t seem to entirely manage the following.

I want to be able to blend between different times in a timeline therefore when entering playmode I create another playable instance of the playableAsset of my director.
Buffer the animationOutput in a variable
Connect the clone timelinePlayable and the original to a mixer and connect the mixer’s output to the original animationOutput. This all works nice and perfect for one Animation track and the bound animator.
However I fail to connect that single mixer (because one should be enough right? it blends all outputs coming from the timelinePlayble?) to multiple animation outputs. With what I currently have it plays mostly the animation of track 1 but on some frames it flickers to track2 :-/

2kqcll

(The code is loosely based on jeffvella’s Timelord github repository)
This is the function that modifies the graph:

private void BuildOutput()
        {
            PlayableDirector.Evaluate();

            if (PlayableDirector.playableGraph.IsValid())
            {
                var trackCount = (PlayableDirector.playableAsset as TimelineAsset)?.outputTrackCount;
                _outputs.Clear();

                Debug.Log("trackcount " + trackCount);

                for (int i = 0; i < trackCount; i++)
                {
                    var originalOutput = (AnimationPlayableOutput)PlayableDirector.playableGraph.GetOutputByType<AnimationPlayableOutput>(i);
                    if (originalOutput.IsOutputValid())
                    {
                        _outputs.Add(originalOutput);
                    }
                }

                Debug.Log("output count " + _outputs.Count);

                if (_outputs.Count > 0)
                {
                    _clone = PlayableDirector.playableAsset.CreatePlayable(PlayableDirector.playableGraph, PlayableDirector.gameObject);
                    _mixer = AnimationMixerPlayable.Create(PlayableDirector.playableGraph, 2);
                    var originalSourcePlayable = _outputs[0].GetSourcePlayable();
                    _mixer.ConnectInput(_cloneIndex, _clone, 0, 0f);
                    _mixer.ConnectInput(_originalIndex, originalSourcePlayable, 0, 1f);

                    for (int i = 0; i < _outputs.Count; i++)
                    {
                        if (_outputs[i].IsOutputValid() && _outputs[i].GetTarget() != null)
                        {
                            var port = _outputs[i].GetSourceOutputPort();
                            _outputs[i].SetSourcePlayable(_mixer, port);
                        }
                    }
                    Debug.Log("TimelineLoop Blendgraph has been build.");
                }
                else
                {
                    Debug.Log("Original Director Output is invalid");
                }
            }
            else
            {
                Debug.Log("Timeline Asset has no animation output");
            }

        }

I thought that this would be the solution or if not the original port just using i as the next possible output port. But both create the same behaviour

var port = _outputs[i].GetSourceOutputPort();
_outputs[i].SetSourcePlayable(_mixer, port);

So yeah, apparently I am not getting something right, I’d be very thankful for your help
kind regards

outputPortIndex on the mixer does not seem to have any effect…
using multiple mixers does not work either because I can not connect the same timeline Playable port to multiple outputs and when I try to explicetely select another output port unity tells me that port does not exist (“attempting to explicitly set an output connection to a non-existing port”) although it looks to as this is what the animation output nodes do…
setting sub tree index on a mixer does nothing and the fact that first track works is a happy accident?

I have an additional question.
As an alternative solution I tried cloning the graph and taking it apart in order to get mixer nodes in before the timelinePlayable. At least this allows me to connect everything the way it should but the animationOffset nodes in the graph copy do not pass any data anymore. Why?

I managed to get a lot closer to the solution I am looking for.

It is very important to recognize the difference between
PlayableDirector.playableGraph.GetOutputCount() and
PlayableDirector.playableGraph.GetOutputCountByType<>() when iterating through the graph because with the regular GetOutputCount the iterator is in sync with the inputs of the timelinePlayable while with ByType it is not.

Furthermore the part of the playableAsset clone that I created, disconnected (beginning with the AnimLayerMixerPlayable next to the red arrow) and attached to the rest of the graph still has some connection to the timelinePlayable that I cloned along with it. Because I only get correct updates of the values that I expect when I attach output nodes to that timelinePlayable.

If I destroy the second timelinePlayable I get Playable is Invalid errors as soon as I get data from that part of the graph.
So what do I have to call on these disconnected nodes in order to fully attach them to my first timelinePlayable?