[2024] Loop Path Keyframes In After Effects With This Expression

To loop path keyframes in After Effects, utilize the built-in expressions for simple animations or apply specific code for more complex paths. This technique automates the looping process, eliminating the need for manual keyframe duplication and streamlining your animation workflow.

November 24, 2023
[2024] Loop Path Keyframes In After Effects With This Expression
"Video editors relying on templates lack genuine skill and creativity."

What do you think? Submit your opinion to see what others have to say!

"It's Like Video Editing On Steroids!"
- Sebastian Navarro, FreeVisuals Editor
Endorsed by Adobe, Motion Array is the ULTIMATE tool for creating high-quality videos! Browse 15M+ assets for Premiere Pro, After Effects, FCPX & DaVinci!

Loop Path Keyframes In After Effects - Expression

After Effects Expressions

Basic Looping Expression for Paths

loopOut("cycle");

This expression loops the path keyframes in a cycle.

Looping with Ping Pong Effect

loopOut("pingpong");

This expression plays the path keyframes forward and then in reverse, creating a ping pong effect.

Looping with Offset

loopOut("offset", 3);

This expression offsets the loop by a certain number of keyframes. In this case, it uses the last three keyframes.

What It Does

In After Effects, while you can easily loop properties like position, scale, or rotation using the built-in loopOut("cycle") expression, paths are a bit trickier. Animated paths have their own unique behavior, which doesn't gel with the default looping expressions. Imagine you've drawn a custom shape using the Pen tool (located at the top toolbar), and you've animated it to morph into another shape over time. Now, if you want this animation to repeat, you'd typically have to duplicate the keyframes manually, which isn't efficient.

How To Use It

You'll soon realize that looping animations can save you a ton of time, especially when working with path keyframes. Let's break this down step by step, so you can grasp the concept and apply it seamlessly in your projects.

Looping a Simple Two-Keyframe Animation

Let's say you've animated a path from frame 0 to frame 20. Here's how you can loop it:

  1. Select the First Keyframe: On your timeline, click on the first keyframe. You'll find this under the property where you've set your path animation, which is usually within a shape layer or mask.
  2. Copy the Keyframe: With the keyframe selected, press Ctrl+C (or Command+C on Mac).
  3. Position the Current Time Indicator (CTI): Move the CTI to double the distance of your second keyframe. In our example, since the second keyframe is at frame 20, you'd move the CTI to frame 40.
  4. Paste the Keyframe: Press Ctrl+V (or Command+V on Mac). You've now created a loop for your two-keyframe animation.

Looping Animations with More Keyframes

For animations with more complexity, say three or more keyframes, the process requires a bit more finesse:

  1. Select All Keyframes Except the Last: On your timeline, click and drag to select all the keyframes, then hold down the Shift key and click on the last keyframe to deselect it.
  2. Copy the Selected Keyframes: Press Ctrl+C (or Command+C on Mac).
  3. Determine the Gap: Look at the time difference between your last two keyframes. For instance, if the second to last keyframe is at frame 60 and the last one is at frame 70, the gap is 10 frames.
  4. Position the CTI: Move the CTI past the last keyframe by the gap you determined. In our example, you'd place the CTI at frame 80.
  5. Paste and Reverse: Press Ctrl+V (or Command+V on Mac) to paste the keyframes. Then, with the newly pasted keyframes selected, go to the top menu and choose Animation > Keyframe Assistant > Time Reverse Keyframes. This creates a "ping pong" effect, making your animation play forward and then in reverse.

The Expression Solution for Path Looping

For those who love diving into the nitty-gritty, there's an expression that can make this whole process even smoother. Expressions in After Effects are snippets of code that automate certain tasks. To apply this:

  1. Select Your Path Property: Click on the stopwatch icon next to the path property while holding the Alt key (or Option key on Mac). This opens the expression editor.
  2. Enter the Looping Expression: Here, you'd input a specific code that calculates the looping based on your keyframes. This code considers the start and end times of your animation and creates a seamless loop.
  3. Apply and Watch: Once the expression is in place, play your animation. You'll see that the path loops seamlessly without the need for manual keyframe duplication.