Skip to main content
rossplaskow
Participant
January 17, 2017
Answered

Anyone got an expression for looping path keyframes?

  • January 17, 2017
  • 4 replies
  • 71387 views

Paths seem to be the only things you can't apply a loop expression to. Is there any other expression that will do the same trick?

I know you can precomp the layer and loop a time remap.

Or you could loop a slider which plays through the animation.

But i'm just looking for an expression to apply to the layer in question, exactly the way we apply loopOut expressions.

Thanks

Ross

Correct answer Roei Tzoref

if (numKeys >1 && time > key(numKeys).time){

  t1 = key(1).time;

  t2 = key(numKeys).time;

  span = t2 - t1;

  delta = time - t2;

  t = delta%span;

  valueAtTime(t1 + t)

}else

  value

courtesy of the Master Expressionist Dan Ebberts in this thread: loopOut pingpong doesn't work on a mask shape? : Adobe After Effects Expressions

4 replies

ACrosby
Known Participant
January 16, 2021

This was very helpful to me ... I'm so glad I found the answer to my problem on an existing support community post rather than having to create a new one. This worked perfectly for looping path animations and even a null object that was being used to animate other visible objects in a hierarchy.
Thanks again!

Participant
December 2, 2020

Hey @Roei Tzoref ! 

 

Your suggestion is great, but do you have a solution for a "pingpong" loop? 

Community Expert
December 3, 2020

To make the expression loop a path animation you'll have to create the ping pong by copying and pasting keyframes, then selecting keyframes and using the Keyframe Assistant to Time Reverse the keyframes if there are more than 2 keyframes. 

 

Here's the workflow for 2 keyframes. 

  • Select the first keyframe and copy
  • Move the CTI past the second keyframe the same distance as it is from the first keyframe and paste.

If your first keyframe is at frame zero and the second keyframe is at frame 20, then move the Current Time Indicator to frame 40 and paste.

 

Here's the workflow for 3 or more keyframes:

  • Select all keyframes except the last keyframe and copy
  • Move the CTI past the last keyframe the same number of frames as the distance between the last two keyframes and paste
  • Make sure the keyframes you just pasted are the only ones selected and select Animation/Keyframe Assistant/Time Reverse keyframes

If the next to the last keyframe is at frame 60 and the last keyframe is at frame 70 the difference is 10 frames so move to frame 80 and paste, then time reverse and you have your pingpong.

 

Participant
July 29, 2020

thank you for your answer, I had the same issue when trying to loop a path in AE. Now it all works out nice and perfect !

Roei Tzoref
Legend
January 17, 2017

when it comes to path property, I found that valueAtTime is what you usually use for an expression.

I also found this while digging around for the same question:

valueAtTime(time % key(numKeys).time)

rossplaskow
Participant
January 17, 2017

That is very helpful. Thanks.
It works if the keyframes begin at the beginning of the composition's time.
Is there a way of making the loop begin from when the first keyframe is?

thanks man!

Roei Tzoref
Roei TzorefCorrect answer
Legend
January 17, 2017

if (numKeys >1 && time > key(numKeys).time){

  t1 = key(1).time;

  t2 = key(numKeys).time;

  span = t2 - t1;

  delta = time - t2;

  t = delta%span;

  valueAtTime(t1 + t)

}else

  value

courtesy of the Master Expressionist Dan Ebberts in this thread: loopOut pingpong doesn't work on a mask shape? : Adobe After Effects Expressions