• Unity
  • Changing mix duration of a timeline clip programmatically

Hi there!

I'm trying to change the mix duration of a clip in runtime:

TimelineClip clip;
clip.template.customDuration = true;
clip.template.mixDuration = 0;

But his changes the values on the actual asset itself, how would I change the mix duration of the actual clip instance (just as if I was doing it in the Unity editor for a specific clip).

Thanks!

Related Discussions
...
  • Изменено

This thread contains a similar question, does this help you?
Dynamic Timeline Binding
Unfortunately the Timeline API is a bit cumbersome in this regard.

Hmm, not sure how to apply that code as it is unclear to me what type playable is and how it relates to the clip. Here are my variables and their types:

PlayableDirector director;
TimelineAsset timeline;
SpineAnimationStateTrack track;
TimelineClip clip; // The clip on the timeline track I wish to modify
SkeletonAnimation skeletonAnimation; // The animation bound to the track

How to access the SpineAnimationStateBehaviour of the clip?

Thanks

You are right, the intermediate code is missing in the other thread. You need to access the director's playableGraph as follows:

PlayableDirector director = this.GetComponent<PlayableDirector>();
int rootCount = director.playableGraph.GetRootPlayableCount();
for (int r = 0; r < rootCount; ++r) {
   Playable rootPlayable = director.playableGraph.GetRootPlayable(r);
   int trackCount = rootPlayable.GetInputCount();
   for (int t = 0; t < trackCount; ++t) {
      var trackPlayable = rootPlayable.GetInput(t);
      if (trackPlayable.GetPlayableType() == typeof(SpineAnimationStateMixerBehaviour)) {
         //ScriptPlayable<SpineAnimationStateMixerBehaviour> behaviour = (ScriptPlayable<SpineAnimationStateMixerBehaviour>)mixerPlayable;
         int clipCount = trackPlayable.GetInputCount();
         for (int c = 0; c < clipCount; ++c) {
            var clipPlayable = trackPlayable.GetInput(c);
            if (clipPlayable.GetPlayableType() == typeof(SpineAnimationStateBehaviour)) {
               ScriptPlayable<SpineAnimationStateBehaviour> stateClip = (ScriptPlayable<SpineAnimationStateBehaviour>)clipPlayable;
               SpineAnimationStateBehaviour animationStateClip = stateClip.GetBehaviour();
               Debug.Log(string.Format("track {0}, clip {1}: {2}", t, c, animationStateClip.animationReference.name));
            }
         }
      }
   }
}

Thanks!